views:

40

answers:

1

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 _user.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.

A: 

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.

Sonia
I still couldn't use "render 'name'" within the user partial...
shmichael
Hmmmm, I've just managed to implement something a bit similar in my app and it works fine - I'm guessing you've tried render 'user/name' in your _user partial?
Sonia
I'm trying to avoid fully-qualifying my partial calls. rendering `user/name` will work, but I don't like the solution.
shmichael