I am getting this error when trying to use the remove link explained in the Railscast: http://railscasts.com/episodes/197-nested-model-form-part-2 error: $(link).previous("input[type=hidden]") is undefined remove_fields()applic...1065175 (line 6) function onclick(event) { remove_fields(this); return false; }()1 (line 2) [Break on this error] $(link).previous("input[type=hidden]").value "1"; in the view file I have : <% echantillon_form.fields_for :treatments do |builder| %> <%= render "treatment", :f => builder %> <% end %> in the partial I have : <p class = "treatmentfields"> <tr> <td class ="name"> type d''examen: </td><td></td><td><%f.text_field :treatmenttype %></td> <td></td> </tr> <tr> <td class ="name"> commentaires sur la preparation : </ td><td></td><td><%= f.text_field :preparation %></td> <td></td> </tr> <%= f.hidden_field :_destroy %> <tr><td><%= link_to_function "remove", "remove_fields(this)" %></td></tr> </p> and in the appliction.js file I have: function remove_fields(link) { $(link).previous("input[type=hidden]").value = "1"; $(link).up(".treatmentfields").hide(); } -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2010-Apr-12 11:22 UTC
Re: $(link).previous("input[type=hidden]") is undefined
On Apr 12, 11:22 am, ES <emsto...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > <%= f.hidden_field :_destroy %> > > <tr><td><%= link_to_function "remove", "remove_fields(this)" > %></td></tr> > > </p> > > and in the appliction.js file I have: > > function remove_fields(link) { > > $(link).previous("input[type=hidden]").value = "1"; > $(link).up(".treatmentfields").hide(); >Looks like because the hidden field and the link don''t have the same parent - the previous function finds you the previous sibling element (matching the selector if specified) Fred -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I had to restructure my page in html so that the link did follow the hidden input field. It works now but when I follow the further instructions in the railscast to have an "add" link to add an object, I get this error: undefined method `render_partial'' for #<ActionView::ReloadableTemplate: 0x9f80d28> this is my view: <% echantillon_form.fields_for :treatments do |builder| %> <%= render "treatment", :f => builder %> <% end %> <%= link_to_add_fields "Add treatment", echantillon_form, :treatments %> On Apr 12, 1:22 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Apr 12, 11:22 am, ES <emsto...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > <%= f.hidden_field :_destroy %> > > > <tr><td><%= link_to_function "remove", "remove_fields(this)" > > %></td></tr> > > > </p> > > > and in the appliction.js file I have: > > > function remove_fields(link) { > > > $(link).previous("input[type=hidden]").value = "1"; > > $(link).up(".treatmentfields").hide(); > > Looks like because the hidden field and the link don''t have the same > parent - the previous function finds you the previous sibling element > (matching the selector if specified) > > Fred-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
the problem was that I didn''t have "_fields" as part of the name of my partial. On Apr 12, 3:24 pm, ES <emsto...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I had to restructure my page in html so that the link did follow the > hidden input field. It works now but when I follow the further > instructions in the railscast to have an "add" link to add an object, > I get this error: > > undefined method `render_partial'' for #<ActionView::ReloadableTemplate: > 0x9f80d28> > > this is my view: > > <% echantillon_form.fields_for :treatments do |builder| %> > <%= render "treatment", :f => builder %> > <% end %> > > <%= link_to_add_fields "Add treatment", > echantillon_form, :treatments %> > > On Apr 12, 1:22 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > On Apr 12, 11:22 am, ES <emsto...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > <%= f.hidden_field :_destroy %> > > > > <tr><td><%= link_to_function "remove", "remove_fields(this)" > > > %></td></tr> > > > > </p> > > > > and in the appliction.js file I have: > > > > function remove_fields(link) { > > > > $(link).previous("input[type=hidden]").value = "1"; > > > $(link).up(".treatmentfields").hide(); > > > Looks like because the hidden field and the link don''t have the same > > parent - the previous function finds you the previous sibling element > > (matching the selector if specified) > > > Fred > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.