On 7 January 2011 21:18, Mauro <[email protected]> wrote:
> In my model I did self.durc_expiry_date = self.durc_issue_date +
> 90.days but I think it is not a best practice to update attributes
> from model.
> So I remove that code and put
> def create
>   �...@supplier = Supplier.new(params[:supplier])
>   �[email protected]_expiry_date = @supplier.durc_issue_date + 90.days
> .......
>
> in the controller.
> But doing so I have no values in durc.expiry.date.

Is there an expiry_date column in the database?  You can only put it
in the controller if that column exists.  However, if the expiry date
is *always* +90 days then you should not put it in the database, but
should provide an instance method in the model, something like

def expiry_date
  self.issue_date + 90.days
end

Then you can say durc.expiry_date and will always get issue date + 90
days.  The method may have to be a little more complex if issue_date
can ever be nil.

Colin


>
> --
> 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.
>
>

-- 
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