I'm using link_to to render a partial (as in, the partial is rendered when the link_to is clicked), as shown. I want to pass the param u.id into the partial but I'm having no success :( What am I doing wrong? I'm desperate.
Edit: Finally got it to work. Here is my code:
In my view, users/show.html.erb - "u" is each Utility in a collection
<% @utilities.each do |u| %>
<%= link_to u.name, { :controller => :users, :action => :show, :util_id => u.id }, :remote => true %>
<% end %>
At the end of my users#show controller method
respond_to do |format|
format.html {
redirect_to @current_user and return
}
format.json {
redirect_to @current_user.json and return
}
format.js {
@util_id = params[:util_id]
redirect_to @current_user and return
}
end
Show.js.erb:
$("#editUtil").prepend('<%= escape_javascript(raw render :partial => "utilEdit", :locals => {:util => params[:util_id]} ).html_safe%>');
My partial: _utilEdit.html.erb
TEST: <%= Utility.find(util).name %>
Thank you to everyone who helped!!