On Dec 15, 2010, at 4:50 PM, Aston J. wrote:

> I have a form for @topic that contains two fields, name(string)
> visible(boolean)
> 
> When the user submits the form, I want to manipulate the contents of the
> attribute :name (which I am able to do - but it's the next part I'm
> stuck on)
> 
> -and then-
> see if a record with the contents of :name already exists
> 
> -if it already exists-
> I want to simple add my user association to it (which I can do by:
> current_user.topics << @topic)
> 
> -if it does not exist-
> then I want to create it as normal
> 
> find_or_create_by_name(params:topic) doesn't seem to work... are there
> any other ways to achieve this?
> 
> (nube alert!)

If it were me I'd be clear about what I'm doing...

name = params[:topic][:name]
# manipulate name here...
@topic = Topic.find_or_create_by_name(name)
current_user.topics << @topic

Only thing i'm not sure about is what you want to do with 'visible'...

-philip

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