Hello people

In my rails 3.0.9 app I'm trying to add nested attributes
dynamically, but I don't want to use "nested form gem"

So I found this example

https://github.com/alloy/complex-form-examples/blob/a234fde4419836f277d7e340657f1d8418911d68/app/helpers/projects_helper.rb

but this code doesn't work

module ProjectsHelper
def remove_link_unless_new_record(fields)
unless fields.object.new_record?
out = ''
out << fields.hidden_field(:_delete)
out << link_to_function("remove", "$
(this).up('.#{fields.object.class.name.underscore}').hide(); $
(this).previous().value = '1'")
out
end
end
end

I think that lines which starts with "out <<" make some conflicts,
because I've checked the html (firebug) and the simbols "<" and ">"
doesn't appear

&lt;a href="#" onclick="$(this).up('.task').hide(); $
(this).previous().value = '1'; return false;"&gt;remove&lt;/a&gt;

Can you help me please?? Thanks

--
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@googlegroups.com.
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.

Search Discussions

  • Angelo Cordova at Nov 7, 2011 at 2:54 pm
    Ok, I've followed this cast http://railscasts.com/episodes/197-nested-model-form-part-2
    but I get an error when I try to add the link to "add fields" (remove
    works as expected) this is the error

    NoMethodError in Projects#new

    Showing /home/angelo/nestattr/app/views/projects/_form.html.erb
    where line #24 raised:

    undefined method `klass' for nil:NilClass

    Extracted source (around line #24):

    21: <%= render "task", :f => t %>
    22: <% end %>
    23: <p>
    24: <%= link_to_add_fields "Add task", f, :task %>
    25: </p>
    26: <div class="actions">
    27: <%= f.submit %>

    Currently I'm using rails 3.0.9, so maybe something has changed since
    then, please, tell me what's wrong

    On 4 nov, 15:48, Angelo Cordova wrote:
    Hello people

    In my rails 3.0.9  app I'm trying to add nested attributes
    dynamically, but I don't want to use "nested form gem"

    So I found this example

    https://github.com/alloy/complex-form-examples/blob/a234fde4419836f27...

    but this code doesn't work

    module ProjectsHelper
    def remove_link_unless_new_record(fields)
    unless fields.object.new_record?
    out = ''
    out << fields.hidden_field(:_delete)
    out << link_to_function("remove", "$
    (this).up('.#{fields.object.class.name.underscore}').hide(); $
    (this).previous().value = '1'")
    out
    end
    end
    end

    I think that lines which starts with "out <<" make some conflicts,
    because I've checked the html (firebug) and the simbols "<" and ">"
    doesn't appear

    &lt;a href="#" onclick="$(this).up('.task').hide(); $
    (this).previous().value = '1'; return false;"&gt;remove&lt;/a&gt;

    Can you help me please?? Thanks
    --
    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@googlegroups.com.
    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedNov 4, '11 at 6:49p
activeNov 7, '11 at 2:54p
posts2
users1
websiterubyonrails.org
irc#RubyOnRails

1 user in discussion

Angelo Cordova: 2 posts

People

Translate

site design / logo © 2021 Grokbase