Hello, I''m having some trouble with forms, my app allows to enter data by using a multi-step form that has 7 steps. There are 3 steps that may let the user to add 1 form, for example there''s a step called "children" and that children has the following fields: * name * age * gender but one father may have more than 1 child and I''m adding another form with ajax by following this http://stackoverflow.com/questions/4812003/adding-fields-dynamically-in-a-nested-model-form-in-rails-3 in the "invite" partial _invite.html.erb <%= fields_for "user[invites_attributes][]", invite do |i| %> <li> <%= link_to("Remove", "#delete", :class => "delete-invite") %> <%= i.label :full_name, "Full Name" %> <%= i.text_field :full_name %> <%= i.label :email, "Email Address" %> <%= i.text_field :email %> </li> <% end %> I''m having some troubles with the first line: <%= fields_for "user[invites_attributes][]", invite do |i| %> What is the correct usage of that? I''m using formtastic and when I made that line but with my fields <%= f.semantic_fields_for ("user[children_attributes][]", user) do |fes| %> and I get this error ............... unexpected '','', expecting '')'' I hope someone can help Thanks in advance -- 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.
On Oct 26, 2011, at 11:53 AM, JavierQQ wrote:> Hello, > > I''m having some trouble with forms, my app allows to enter data by > using a multi-step form that has 7 steps. > There are 3 steps that may let the user to add 1 form, for example > there''s a step called "children" > and that children has the following fields: > * name > * age > * gender > but one father may have more than 1 child and I''m adding another form > with ajax by following this > http://stackoverflow.com/questions/4812003/adding-fields-dynamically-in-a-nested-model-form-in-rails-3I haven''t followed that particular tutorial, but I have used the Railscasts (73 - 75) and Ryan Bates'' fabulous nested_form gem. Note that the ''casts show how to do it long-hand, and the gem simply wraps up all that work and puts a bow on it. You can probably simply follow the directions from the gem and get on with your life if you already know the theory. Walter> > in the "invite" partial > _invite.html.erb > <%= fields_for "user[invites_attributes][]", invite do |i| %> > <li> > <%= link_to("Remove", "#delete", :class => "delete-invite") %> > <%= i.label :full_name, "Full Name" %> > <%= i.text_field :full_name %> > <%= i.label :email, "Email Address" %> > <%= i.text_field :email %> > </li> > <% end %> > > I''m having some troubles with the first line: <%= fields_for > "user[invites_attributes][]", invite do |i| %> > What is the correct usage of that? I''m using formtastic and when I > made that line but with my fields > > <%= f.semantic_fields_for ("user[children_attributes][]", user) > do |fes| %> > > and I get this error > > ............... unexpected '','', expecting '')'' > > I hope someone can help > > Thanks in advance > > -- > 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. >-- 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.
On 26 October 2011 16:53, JavierQQ <jquarites-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello, > > I''m having some trouble with forms, my app allows to enter data by > using a multi-step form that has 7 steps. > There are 3 steps that may let the user to add 1 form, for example > there''s a step called "children" > and that children has the following fields: > * name > * age > * gender > but one father may have more than 1 child and I''m adding another form > with ajax by following this > http://stackoverflow.com/questions/4812003/adding-fields-dynamically-in-a-nested-model-form-in-rails-3 > > in the "invite" partial > _invite.html.erb > <%= fields_for "user[invites_attributes][]", invite do |i| %> > <li> > <%= link_to("Remove", "#delete", :class => "delete-invite") %> > <%= i.label :full_name, "Full Name" %> > <%= i.text_field :full_name %> > <%= i.label :email, "Email Address" %> > <%= i.text_field :email %> > </li> > <% end %> > > I''m having some troubles with the first line: <%= fields_for > "user[invites_attributes][]", invite do |i| %> > What is the correct usage of that? I''m using formtastic and when I > made that line but with my fields > > <%= f.semantic_fields_for ("user[children_attributes][]", user)You should not have a space between semantic_fields_for and (. That is ruby syntax. Whether it fixes you problem is another matter. Colin> do |fes| %> > > and I get this error > > ............... unexpected '','', expecting '')'' > > I hope someone can help > > Thanks in advance > > -- > 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. > >-- gplus.to/clanlaw -- 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.
On Oct 26, 2011, at 11:53 AM, JavierQQ wrote:> Hello, > > I''m having some trouble with forms, my app allows to enter data by > using a multi-step form that has 7 steps. > There are 3 steps that may let the user to add 1 form, for example > there''s a step called "children" > and that children has the following fields: > * name > * age > * gender > but one father may have more than 1 child and I''m adding another form > with ajax by following this > http://stackoverflow.com/questions/4812003/adding-fields-dynamically-in-a-nested-model-form-in-rails-3 > > in the "invite" partial > _invite.html.erb > <%= fields_for "user[invites_attributes][]", invite do |i| %> > <li> > <%= link_to("Remove", "#delete", :class => "delete-invite") %> > <%= i.label :full_name, "Full Name" %> > <%= i.text_field :full_name %> > <%= i.label :email, "Email Address" %> > <%= i.text_field :email %> > </li> > <% end %> > > I''m having some troubles with the first line: <%= fields_for > "user[invites_attributes][]", invite do |i| %> > What is the correct usage of that? I''m using formtastic and when I > made that line but with my fields > > <%= f.semantic_fields_for ("user[children_attributes][]", user) > do |fes| %> > > and I get this error > > ............... unexpected '','', expecting '')'' > > I hope someone can help > > Thanks in advanceI think that the space after f.semantic_fields_for and the parentheses around the argument list are interacting to produce the error. I think that you can probably do either fix and resolve the issue: <%= f.semantic_fields_for "user[children_attributes][]", user do | fes| %> <%= f.semantic_fields_for("user[children_attributes][]", user) do |fes| %> -Rob Rob Biedenharn Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org http://AgileConsultingLLC.com/ rab-/VpnD74mH8+00s0LW7PaslaTQe2KTcn/@public.gmane.org http://GaslightSoftware.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-/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.
Thanks for your reply, I''ve seen that cast, but when I add another form for another children the HTML shows this <input id="user_children_attributes_0_name" maxlength="255" name="user[children_attributes][0][name]" type="text"> so it''s not increasing and it will only save the first child and now I''m trying what the cast says _children.html.erb <%= f.semantic_fields_for "user[children][]", user do |children| %> ..... <% end %> and I get this undefined local variable or method `user'' It''s maybe something I''m not seeing, I''m starting with rails and I hope someone can help me Thanks On Wed, Oct 26, 2011 at 11:06 AM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 26 October 2011 16:53, JavierQQ <jquarites-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hello, > > > > I''m having some trouble with forms, my app allows to enter data by > > using a multi-step form that has 7 steps. > > There are 3 steps that may let the user to add 1 form, for example > > there''s a step called "children" > > and that children has the following fields: > > * name > > * age > > * gender > > but one father may have more than 1 child and I''m adding another form > > with ajax by following this > > > http://stackoverflow.com/questions/4812003/adding-fields-dynamically-in-a-nested-model-form-in-rails-3 > > > > in the "invite" partial > > _invite.html.erb > > <%= fields_for "user[invites_attributes][]", invite do |i| %> > > <li> > > <%= link_to("Remove", "#delete", :class => "delete-invite") %> > > <%= i.label :full_name, "Full Name" %> > > <%= i.text_field :full_name %> > > <%= i.label :email, "Email Address" %> > > <%= i.text_field :email %> > > </li> > > <% end %> > > > > I''m having some troubles with the first line: <%= fields_for > > "user[invites_attributes][]", invite do |i| %> > > What is the correct usage of that? I''m using formtastic and when I > > made that line but with my fields > > > > <%= f.semantic_fields_for ("user[children_attributes][]", user) > > You should not have a space between semantic_fields_for and (. That > is ruby syntax. Whether it fixes you problem is another matter. > > Colin > > > do |fes| %> > > > > and I get this error > > > > ............... unexpected '','', expecting '')'' > > > > I hope someone can help > > > > Thanks in advance > > > > -- > > 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. > > > > > > > > -- > gplus.to/clanlaw > > -- > 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. > >-- 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.
In the casts I''ve seen this <div id="tasks"> <%= render :partial => ''task'', :collection => @project.tasks %> </div> so as far as I understand theres a file _task.html.erb, but they create tasks by building it in the controller should I do something like that?, I mean <%= render "children", :collection => @user.childrens %> On 26 oct, 11:17, Javier Quarite <jquari...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks for your reply, > > I''ve seen that cast, but when I add another form for another children the > HTML shows this > > <input id="user_children_attributes_0_name" maxlength="255" > name="user[children_attributes][0][name]" type="text"> > > so it''s not increasing and it will only save the first child > > and now I''m trying what the cast says > > _children.html.erb > > <%= f.semantic_fields_for "user[children][]", user do |children| %> > ..... > <% end %> > > and I get this > > undefined local variable or method `user'' > > It''s maybe something I''m not seeing, I''m starting with rails and I hope > someone can help me > > Thanks > > > > > > > > On Wed, Oct 26, 2011 at 11:06 AM, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > On 26 October 2011 16:53, JavierQQ <jquari...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hello, > > > > I''m having some trouble with forms, my app allows to enter data by > > > using a multi-step form that has 7 steps. > > > There are 3 steps that may let the user to add 1 form, for example > > > there''s a step called "children" > > > and that children has the following fields: > > > * name > > > * age > > > * gender > > > but one father may have more than 1 child and I''m adding another form > > > with ajax by following this > > >http://stackoverflow.com/questions/4812003/adding-fields-dynamically-... > > > > in the "invite" partial > > > _invite.html.erb > > > <%= fields_for "user[invites_attributes][]", invite do |i| %> > > > <li> > > > <%= link_to("Remove", "#delete", :class => "delete-invite") %> > > > <%= i.label :full_name, "Full Name" %> > > > <%= i.text_field :full_name %> > > > <%= i.label :email, "Email Address" %> > > > <%= i.text_field :email %> > > > </li> > > > <% end %> > > > > I''m having some troubles with the first line: <%= fields_for > > > "user[invites_attributes][]", invite do |i| %> > > > What is the correct usage of that? I''m using formtastic and when I > > > made that line but with my fields > > > > <%= f.semantic_fields_for ("user[children_attributes][]", user) > > > You should not have a space between semantic_fields_for and (. That > > is ruby syntax. Whether it fixes you problem is another matter. > > > Colin > > > > do |fes| %> > > > > and I get this error > > > > ............... unexpected '','', expecting '')'' > > > > I hope someone can help > > > > Thanks in advance > > > > -- > > > 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-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.orgm. > > > 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. > > > -- > > gplus.to/clanlaw > > > -- > > 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.-- 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.
On Oct 26, 2011, at 12:17 PM, Javier Quarite wrote:> Thanks for your reply, > > I''ve seen that cast, but when I add another form for another children the HTML shows this > > <input id="user_children_attributes_0_name" maxlength="255" name="user[children_attributes][0][name]" type="text"> > > so it''s not increasing and it will only save the first child > > and now I''m trying what the cast says > > _children.html.erb > > <%= f.semantic_fields_for "user[children][]", user do |children| %> > ..... > <% end %> > > and I get this > undefined local variable or method `user'' > > It''s maybe something I''m not seeing, I''m starting with rails and I hope someone can help meHere''s an extraction from a site that''s using Ryan''s plug-in (a person can have N images): #people_controller.rb ... def new @person = Person.new @person.images.build end ... #person.rb class Person < ActiveRecord::Base attr_accessible :images_attributes, :name, :sort_name, :birth, :death, :nationality, :historical_period, :short_description, :bio has_many :images, :as => :attachable, :dependent => :destroy accepts_nested_attributes_for :images, :reject_if => lambda { |a| a[:file].blank? && a[:file_uid].blank? && a[:file_url].blank? && a[:name].blank? }, :allow_destroy => true validates :name, :presence => true validates :nationality, :presence => true validates :historical_period, :presence => true end #image.rb class Image < ActiveRecord::Base attr_accessible :name, :attachable_type, :attachable_id, :file_name, :file_url, :file_uid, :file, :retained_file, :remove_file, :created_at, :file_height, :updated_at, :file_width image_accessor :file belongs_to :attachable, :polymorphic => true def label name.blank? ? file_name : name end end #people/_form.html.erb <%= nested_form_for @person, :url => person_path(@person, :page => params[:page]), :html => {:multipart => true} do |f| %> <%= f.error_messages %> ... <div id="images" class="tabbed"> <%= f.fields_for :images %> <p class="clear-both"> <%= f.link_to_add "Add an image", :images %> </p> </div> <p><%= f.submit %></p> <% end %> #people/_image_fields.html.erb (this name is critical to success) <p class="clear-both image"> <%- if f.object.file_uid -%> <span class="left"> <%= link_to( image_tag( f.object.file.thumb(''60x60#'').url, :class => ''border'', :size => ''60x60'' ), f.object.file.url, :target => ''_blank'') %><br /><span class="hint"><%= f.object.file_width %> × <%= f.object.file_height %></span> </span> <%= f.link_to_remove "Delete", :class => ''delete'' %> <%- else -%> <span class="left"> <%= image_tag( ''thumb_new.jpg'', :class => ''border'', :size => ''60x60'' ) %> </span> <%- end -%> <%= f.label :name %> <%= f.text_field :name %><br /> <%= f.label :file, "Upload" %> <%= f.file_field :file %> <%= f.hidden_field :retained_file %><br /> <%= f.label :file_url, "Upload From URL" %> <%= f.text_field :file_url %> </p> That is quite literally all there is to it, except to follow the rest of the install directions on the Github page. Walter> > Thanks > > On Wed, Oct 26, 2011 at 11:06 AM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > On 26 October 2011 16:53, JavierQQ <jquarites-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hello, > > > > I''m having some trouble with forms, my app allows to enter data by > > using a multi-step form that has 7 steps. > > There are 3 steps that may let the user to add 1 form, for example > > there''s a step called "children" > > and that children has the following fields: > > * name > > * age > > * gender > > but one father may have more than 1 child and I''m adding another form > > with ajax by following this > > http://stackoverflow.com/questions/4812003/adding-fields-dynamically-in-a-nested-model-form-in-rails-3 > > > > in the "invite" partial > > _invite.html.erb > > <%= fields_for "user[invites_attributes][]", invite do |i| %> > > <li> > > <%= link_to("Remove", "#delete", :class => "delete-invite") %> > > <%= i.label :full_name, "Full Name" %> > > <%= i.text_field :full_name %> > > <%= i.label :email, "Email Address" %> > > <%= i.text_field :email %> > > </li> > > <% end %> > > > > I''m having some troubles with the first line: <%= fields_for > > "user[invites_attributes][]", invite do |i| %> > > What is the correct usage of that? I''m using formtastic and when I > > made that line but with my fields > > > > <%= f.semantic_fields_for ("user[children_attributes][]", user) > > You should not have a space between semantic_fields_for and (. That > is ruby syntax. Whether it fixes you problem is another matter. > > Colin > > > do |fes| %> > > > > and I get this error > > > > ............... unexpected '','', expecting '')'' > > > > I hope someone can help > > > > Thanks in advance > > > > -- > > 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. > > > > > > > > -- > gplus.to/clanlaw > > -- > 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. > > > > -- > 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.-- 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.