Is it possible to render a partial when a link is clicked?
I have sear开发者_运维问答ched google and here but I can't find anything useable.
Thanks
Yes it is possible. The following example uses jQuery, as you tagged it :
In your view file (the page that is actually displayed) :
<%= link_to "Display a new view", path_to_controller, :remote => true %>
In your controller action (path_to_controller), add a js response :
respond_to do |format|
format.js
end
And in the path_to_controller.js.erb (the js response file) :
$("#your-placeholder-id").prepend('<%= escape_javascript(render 'path/to/view') %>');
Hope that helps!
精彩评论