Got it working with:
def after_initialize
self.date ||= Date.today
end
...hopefully I won't be pressing my luck, but one last question (for
now). So I have a bunch of form fields that I need to add up their
values, and make sure their sum does not except the value entered in a
new form field. If the sum does exceed the form field value then I
want to alert the user and prevent it from saving. Basically I want to
validate that :atWorkHours.value > ( :hoursMeetings.value
+ :hoursTraining.value + :hoursProjTrav.value )
I tried to do something similar to this in my model...but I assume I
just had the syntax completely wrong.
Last question/request for the day I promise!
Thanks,
Justin :)
On Mar 5, 11:55 am, Andy Jeffries <[email protected]> wrote:
> > When I add this to my model:
>
> > def after_initialize
> > :date = Date.today
> > end
>
> > I get this error -- /home/xxdesmus/timetool/app/models/post.rb:38:
> > syntax error, unexpected '=', expecting kEND :date = Date.today ^
>
> You will do, you're trying to assign a value to a symbol (which is an
> immutable object).
>
> > when I try it this way:
>
> > def after_initialize
> > date = Date.today
> > end
>
> > It doesn't do anything ...probably because my field should have a
> > different name other than "date" huh?
>
> def after_initialize
> self.date = Date.today
> end
>
> Doing:
>
> date =
>
> Will just assign the value to a local variable.
>
> Cheers,
>
> Andy
--
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.