Bryan,
Here is the code that I used to get it work. Note that without the
visibility.nil? check, the new record took on the first record and the one that
I selected in the form.
def after_initialize
if new_record? && self.visibility.nil?
self.visibility = Visibility.first
end
end
Thanks for your help!
Steve
On 2010-06-09, at 11:56 AM, Bryan Larsen wrote:
There are at least 3 ways. Usually #1 is the right way, but there
are exceptions.
1) Model side:
def after_initialize
if new_record? && !user.nil?
country = user.country
end
end
2) Controller/view side in Ruby code:
<% this.country = Country.first if this.country.nil? %>
3) set the include-none option to false on your select-one.
Bryan
On Jun 9, 9:04 am, Steve Pallen <[email protected]> wrote:
> Let's say I a blog post model and an association with a categories
> model. When I create a new post, the default on the form is no
> category. How do I set it up so that one of my categories is the
> default for a new post?
>
> Thanks,
> Steve
--
You received this message because you are subscribed to the Google Groups "Hobo
Users" 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/hobousers?hl=en.
--
You received this message because you are subscribed to the Google Groups "Hobo
Users" 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/hobousers?hl=en.