Hi,
I have the following:
_list_user.rhtml
<% for column in User.content_columns %>
<%= column.human_name %> |
<% end %>
<% for user in @users %>
<% for column in user.content_columns %>
<%=h user.send(column.name) %> |
<% end %>
<td><%= link_to 'Edit', :action => 'user', :id => user, :user_info
=> @user_info %>
<%= link_to ‘Destroy’, { :action => ‘destroy_user’, :id =>
user, :user_info => @user_info }, :confirm => ‘Are you sure?’, :post
=> true %> |
<% end %>
_______________________________________
user.rhtml
<%= render :partial => 'list_user', :user_info => @user_info %>
<% form_remote_tag :url => { :action => ‘update_user’, :id =>
@user, :user_info => @user } do %>
<%= render :partial => ‘user_form’ %>
<%= submit_tag ‘Save’ %>
<% end %>
update_user.rjs
page.replace_html(“list_user”, :partial => ‘list_user’, :user_info =>
@user_info )
For some reason, when I click on “Save”, it doesn’t update the
_list_user.rhtml partial. In fact, it updates the model but the
partial doesn’t refresh. Is there something wrong with the partial?
I put page.alert(‘RJS works!’) in my update_user.rjs and that
works…
Thanks in advance!
So I looked into this a little more and it seems like the new updated
data doesn’t get refreshed right after I click “save”. When I refresh
the page again, that’s when the data is refreshed. I’m not sure how
the form submits to the server, but apparently the page.replace_html
happens BEFORE the data is submitted. Any ideas?
On 3/3/07, wcheung [email protected] wrote:
I have the following:
[…]
For some reason, when I click on “Save”, it doesn’t update the
_list_user.rhtml partial. In fact, it updates the model but the
partial doesn’t refresh. Is there something wrong with the partial?
I put page.alert(‘RJS works!’) in my update_user.rjs and that
works…
The explanation I can think of is that you didn’t fetch the @users
in the update_user action in your controller. That’s how you see
the data when you refresh the page (since you must have fetched
@users in your users action) but not in the RJS update.
d.
On 3/3/07, wcheung [email protected] wrote:
Hmm…I have @users in update_user action (it was complaining before in
the log). But it’s still not updating the data before the
page.replace_html. Any other ideas? Is there anything I’m doing
wrong with the form?
Having re-read your snippets, there is one line that really troubles me:
page.replace_html(“list_user”, :partial => ‘list_user’,
:user_info=>@user_info )
I don’t think this line will work. Your partial is using the @user_info
in the
controller, that the one passed by the line above. So if your action
doesn’t
fetch @user_info, there’s no data for the partial to use.
To pass a “local variable” to the template, pass
:locals=>{:user_info=>@user_info}
in the render parameter, then replace the member variable @user_info
with user_info in the partial. Hope this works.
d.
Hmm…I have @users in update_user action (it was complaining before in
the log). But it’s still not updating the data before the
page.replace_html. Any other ideas? Is there anything I’m doing
wrong with the form?