I am having trouble rendering a partial called ''names'' through
a submit
tag located within that partial. The form data is saving with my current
code. However, the existing data is not loading into the form and the
partial is not being re-rendered upon submission to reveal the changes
to this data.What might I do to fix this?
show.rhtml
<%= javascript_include_tag :defaults %>
<ul id="name_list"><%= render :partial =>
''names'', :object => @person
%></ul>
_names.rhml (lists the names of ''Person''. Clicking on a name
reveals a
form to edit that name)
<% for name in @person.current_names %>
<%= link_to_function (name.full_name, :onclick =>
"Element.show(''edit_name_#{claimantname.id}'')"
%><br>
<div id="edit_name_<%= claimantname.id %>"
style="display:none;">
<%= form_remote_tag(:url => {:action =>
''update_name'', :id => name}
)%>
<%= text_field ''name'', ''first_name''
%>
<%= text_field ''name'', ''last_name''
%>
<%= submit_tag ''Edit'', :onclick =>
"Element.hide(''edit_name_#{name.id}'')"
%></tr>
<%= end_form_tag %>
</div>
<% end %>
persons_controller
def update_name
@name = Name.find(params[:id])
if @name.update_attributes(params[:name])
return if request.xhr?
render :partial => ''names''
end
end
update_name.rjs
Code : ruby - fold - unfold
page.replace_html("name_list", :partial => "names",
:object => @person)
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
> def update_name > @name = Name.find(params[:id]) > if @name.update_attributes(params[:name]) > return if request.xhr? > render :partial => ''names'' > > update_name.rjs > > page.replace_html("name_list", :partial => "names", :object => @person)- There''s no @person instance variable defined by the update_name action. - text_field ''name'', ''last_name'' assumes there''s an instance variable @name, which there isn''t in your case. One way round it is to do this <% form_remote_for(:name, name, :url => {:action => ''update_name'', :id => name}) do |f| %> <%= f.text_field :first_name %> ... <% end %> Fred -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> - There''s no @person instance variable defined by the update_name > action. > - text_field ''name'', ''last_name'' assumes there''s an instance variable > @name, which there isn''t in your case. One way round it is to do this > > <% form_remote_for(:name, name, :url => {:action => ''update_name'', :id > => name}) do |f| %> > <%= f.text_field :first_name %> > ... > <% end %> > > > FredRight on about the @person instance variable. form_remote_for used as you suggested loads my data into the fields fine: <% form_remote_for(:name, name, :url => {:action => ''update_name'', :id => name}) do |f| %> <%= f.text_field :first_name %> <%= f.text_field :last_name %> <%= submit_tag ''Edit'' %> <% end %> However, it no longer saves my changes. Is there something I need to change in the controller or submit tag as well? Thanks for your help. Peter -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---