It is overwritten because the objective requires a user_id which comes
from a different place than the other attributes.  I could simply use
create and add more code at the controller level but I prefer to push
that down to the model.

On Oct 25, 2:15 pm, Marnen Laibow-Koser <rails-mailing-l...@andreas-
s.net> wrote:
> drewB wrote:
>
> [...]> Code:
>
>
>
>
>
> > class Objective < ActiveRecord::Base
> >   belongs_to :user
> >   has_many :next_actions, :order => 'id DESC', :conditions =>
> > {:completed => false}
> >   has_many :action_items, :order => 'position'
> >   has_many :progress_updates
>
> >   serialize :freq_value
>
> > validates_presence_of :name, :due_date, :completion, :pr_u_frequency_id
> >   validates_numericality_of :completion, :only_integer =>
> > true, :greater_than_or_equal_to => 0, :less_than_or_equal_to => 100
>
> > def self.create(attributes, user_id)
> >     #create new record with user_id correctly set
> >     attributes.delete :freq_options #deletes this unused key
> >     obj = self.new(attributes)
> >     obj.user_id = user_id
> >     obj.save ? obj : nil
>
> >   end
>
> I don't know if this is directly related to your problem, but why are
> you overriding AR::Base.create ? You shouldn't need to; just do
> @user.objectives.create(attributes).  You're trying to reinvent what AR
> already gives you for free.
>
> > end
>
> [...]
>
> Best,
> --
> Marnen Laibow-Koserhttp://www.marnen.org
> [email protected]
> --
> Posted viahttp://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 [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