So I was wondering how to work with the link_to method and ajax in Rails 3, when redering different partials.
Example:
Let say I have two link in show.html.erb
and every link have a partial to render.
<li><%= link_to "Group1", user_path(@user), { :action => 'group1' , :method => :get, :remote => true} %></li>
<li><%= link_to "Group2", user_path(@user), { :action => 'group2' , :method => :get, :remote => true} %></li>
And we are going to render the partials in this div:
<div id="profile-data">
...render here...
</div>
In the UsersController
we have our call methods for each partial:
def group1
respond_to do |format|
format.js
end
end
def group2
respond_to do |format|
format.js
end
end
And of course we have our js files in the view user folder:
group1.js.erb
$("#profile-data").html("<%= escape_javascript(render(:partial => 'group1')) %>");
group2.js.erb
$("#profile-data").html("<%= escape_javascript(render(:partial => 'group2')) %>");
So my question is: is this the right way to render different partials with ajax? Are I missing something? Do have to route them some way?
This code dosent work right now and I dont know why, any help would be appreciated.