0

I'm using rails3.

User model has one user_profile.
I just installed devise and its working fine.

I made registrations_controller.rb and it has 'create', 'after_update_path_for(resource) ', and 'edit' actions.

If I want to make it input '45' to nested column of user_profile as default value, how can I code in registration controller???

Should I make another action called 'save/or new?' , and write this?

@user.user_profile.language_id = '45'

HUSTEN
  • 5,117
  • 4
  • 24
  • 38
  • I suggest you take a look at nested_attributes. Here are a few links: http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html, http://railscasts.com/episodes/196-nested-model-form-part-1, http://stackoverflow.com/questions/4867880/nested-attributes-in-rails-3 – John Naegle Dec 19 '12 at 03:01

1 Answers1

0

If you just want a default value for a particular field you can add this to your migration file like...

create_table :user_profile do |t|
  ...
  t.integer :language_id, :default => 45
end

...this will automatically set the lauguage_id value with the association is created.

Mark Locklear
  • 5,044
  • 1
  • 51
  • 81