Loading...

WellRailed@googlegroups.com

[Prev] Thread [Next]  |  [Prev] Date [Next]

Re: [WellRailed] A question of style Andy Newport Thu Feb 02 16:09:55 2012

Thinking about your domain will always determine that for you, paid and pay
don't sound like action that a project would undertake unless the project
was paying for something.

project.process_payment! feels slightly better but without knowing the
project object's domain requirements could be just as stupid.

If you're setting attributes in a controller you should definitely call
save in the controller, but if you're telling the object to do something it
should do it.

Finally, pet peeve, call save! unless you have a good reason not to.
Explodey failure trumps silent failure always...

def process_payment!
  # do stuff regarding payment
  self.state = PAID
  save!
end

On Wed, Jan 25, 2012 at 10:01 AM, Henry Maddocks
<[EMAIL PROTECTED]>wrote:

> Something that has bothered me for a while is should model methods that
> set attributes call save or should the caller do it?
>
> ie. This...
>
> class Project < ActiveRecord::Base
>   def paid
>     self.state = PAID
>     self.save
>   end
>
> end
>
> or this...
>
> my_project.paid
> my_project.save
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "WellRailed" 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/wellrailed?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"WellRailed" 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/wellrailed?hl=en.