Aston J. wrote in post #968740:
> 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
>
> This is so I don't end up with duplicate 'topics' in my DB.
>
> find_or_create_by_name(params:topic) doesn't seem to work...

Did you mean find_or_create_by_name(params[:topic][:name])?  And what do 
you mean by "doesn't seem to work"?  In general, it's best if you 
describe what happened as clearly as possible.

 are there
> any other ways to achieve this?
>
> (I'm a nube)
>
> Thanks in advance.

Best,
-- 
Marnen Laibow-Koser
http://www.marnen.org
mar...@marnen.org

Sent from my iPhone

-- 
Posted via http://www.ruby-forum.com/.

-- 
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 rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to