开发者

Rendering an RJS of controller A in context of controller B

This has been asked before, but didn't receive a proper answer:

I have a User that has Files. When a File is updated (via AJAX) I want to refresh the User view.

I do this in RJS:

page['user'].replace_html :partial => 'users/user'

However, the _u开发者_StackOverflow社区ser.erb.html partial references other partials in the users directory, and e.g. for _name.erb.html Rails complains it can't find the template Files/name. (I want it to look for Users/name).

Is there a way to change the context of the view rendering to that of controller Users? I'd hate to fully-qualify all of the partial rendering requests.


Maybe try moving the _user.html.erb partial to a 'shared' folder? So the RJS would become:

page['user'].replace_html :partial => 'shared/user'

See http://api.rubyonrails.org/classes/ActionView/Partials.html - a local variable may also need to be defined.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜