I have my js.erb file called remotely from my Rails 5.0.4 app.
<% if @admin_invitation.present? && @admin_invitation.valid? %>
<%my_view = j (render partial: "shared/invitation_card",:user => @admin_invitation.invited_id, :email => @admin_invitation.invited_email, :type => "admin" ) %>
$(".invites.admins .row").prepend("<%=my_view %>");
<% end %>
App.refresh( "<%= j(render 'shared/alerts') %>" );
It works as expected when i hardcode the values in the partial, but when i feed them in as locals from this js.erb file, they dont come through (nil). Worth noting that I render the partial from a a non-remote haml view and it works just fine.
Here are the ways of rendering i have tried (I know some are outdated, but just for a sanity check)
render partial: "shared/invitation_card", :locals=> { :email => "[email protected]", :type => "admin" }
render partial: "shared/invitation_card", object: "[email protected]", as: "email"
render partial: "shared/invitation_card", email: "[email protected]", type:"admin"
render partial: "shared/invitation_card", locals: { email: "[email protected]", type: "admin" }
Anyone else have issues with rendering haml partials from a js.erb in rails 5?
EDIT:
Here is the controller method calling the js.erb above.
def create
if params[:invited_status] == "temporary_invitation_user"
result = CreateGroupInvitation.call(invitation_model: GroupFollowInvitation, group_id: params[:group_id], inviter: current_user, invited_email: params[:invited_email], notification: "created_group_follow_email_invitation")
else
result = CreateGroupInvitation.call(invitation_model: GroupFollowInvitation, group_id: params[:group_id], inviter: current_user, invited_id: params[:invited_id] , notification: "created_group_follow_invitation")
end
if result.success?
@invitation = result.invitation
@invited = params[:invited_id] == "null" ? params[:invited_email] : User.find(params[:invited_id])
flash.now[:success] = "Your follow invitation was sent"
else
if result.error_message.present?
flash.now[:info] = result.error_message
else
flash.now[:error] = "An error happend"
end
end
respond_to do |format|
format.js { render layout: false }
end
end