Hi All, I''m trying to learn Ruby on Rails and have got an issue with the validation of a nested form. I think I have got it setup correctly as it appears to be saving the data as expected, but it is not wrapping the CSS class (field_with_errors) to the fields, and if data is entered into the nested fields it disappears on form submit (if there are validation errors). The validation messages are being displayed correctly. Here are the relevant bits of code (some of the forms have been ommitted) - I am hoping somebody more experienced will be able to spot where I have gone wrong! /app/models/user.rb class User < ActiveRecord::Base has_one :feature accepts_nested_attributes_for :feature end /app/models/feature.rb class Feature < ActiveRecord::Base belongs_to :user validates :profile, :hobbies, :presence => true end /app/views/users/_form.html.erb <% @user.build_feature %> <%= form_for @user, :url => { :controller => :users, :action => "create" } do |user| %> <%= user.text_field :email %> <%= render :partial => ''features/form'', :locals => { :form => user } %> /app/views/features/_form.html.erb <%= form.fields_for :feature do |f| %> <%= f.text_area :profile %> Debugging @user.errors shows the subform items are being outputted as follows: :"feature.profile": can''t be blank Wheras the other form shows the error messages being output: :first_name: can''t be blank I''ve googled this issue but haven''t found anything that has worked - would appreciate any help! Thanks -- 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-/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.
OK so I have had a bit of a breakthrough - the form works great when the association is changed to has_many rather than has_one What do I need to change to get this working for a has_one association? Thanks in advance! -- 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-/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.
well what the output params look like? you have tu take the feature from params and add it to user. On Thu, Mar 3, 2011 at 4:48 PM, Dan Th <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> OK so I have had a bit of a breakthrough - the form works great when the > association is changed to has_many rather than has_one > > What do I need to change to get this working for a has_one association? > > Thanks in advance! > > -- > 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-/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.