Begin with ajax and jquery combined with rails, I am trying to create a \"load more\" link in the bottom of my user index page. My user index page should d
You shouldn't need to create another action for it. I would use unobtrusive javascript. Try something like this:
User_controller.rb
you shouldn't need to change anything here, just make sure the controller responds to js
respond_to :html, :js
User/index.html.erb
<%= render :partial => @users %>
<%= link_to_next_page @users, 'Load More', :remote => true, :id=>"load_more_link" %>
<%### link_to_next_page is a Kaminari function that returns exactly what the name implies %>
User/index.js.erb
$('#users').append("<%= escape_javascript(render :partial => @users)%>");
$('#load_more_link').replaceWith("<%= escape_javascript(link_to_next_page(@users, 'Load More', :remote => true, :id=>'load_more_link'))%>");
That should be all that is needed to get it working. Of course you can add some javascript to insert a loading icon when the link is clicked or whatever. Note: I haven't tested this exact implementation, so there may be some errors, but you should be able to get the idea