开发者

Render partial onclick in rails

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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜