Hiya

I am looking at Rails 2.3.2 and how to cleanly do the following:

 -  I have model User
 -  User has many Plans
 -  User has one Active Plan
 -  New User form has fields on it to create the Active Parent

I want to create a new User with an Active Plan in one form.

At the moment I have:

class User < ActiveRecord::Base
 has_one  :active_plan, :class_name => 'Plan', :conditions =>
['active = ?', true]
 has_many :plans

 def active_plan_attributes=(attributes)
   plans.build(attributes.merge(:active => true))
 end
end

So that in the form I can wrap the active plan fields in:

<% f.fields_for :active_plan, @active_plan do |ap| %>
...
<% end %>

The @active_plan is being set in the user controller new action atm.

Is this the cleanest approach, or is there something else I can use?
accepts_nested_attributes_for did not seem to suit to set the plan to
being active ... but could be missing something on that?

cheers
rich

--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to