> Thanks for the reply both. Does this make it any clearer? It is my
> create action based on what Philip said - but it does not work:
> Topic(#2171041280) expected, got Hash(#2151972860)
You're trying to add a hash to an AR association... Rails doesn't like that :)
> def hashtag(name)
> string = name
> return name = string if string.split.count <= 1
> name = string.split.map{|w| w.capitalize}.join
> end
Take a look at the titleize() method and get rid of hashtag entirely...
http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-titleize
>
> def create
> name = params[:topic][:name]
> visible = params[:topic][:visible]
> hashtag(name)
> @topic = {:name => "#{name}", :visible => visible}
What is visible? If visible is related to the user's ability to see that topic
then it shouldn't be set in the topic itself.
You'll need an intermediate model (look up has many through) to handle that.
Ignoring that for now...
def create
name = params[:topic][:name].titleize
@topic = Topic.find_or_create_by_name(name)
current_user.topics << topic
redirect_to @topic, :notice => 'Topic was successfully created.'
end
>
> if
> Topic.where(:name => "#{name}")
> current_user.topics << @topic
> redirect_to(@topic, :notice => 'Topic was successfully created.')
> elsif
> Topic.create(@topic)
> current_user.topics << @topic
> redirect_to(@topic, :notice => 'Topic was successfully created.')
> else
> render :action => "new"
> end
> end
>
> View as pastie here: http://pastie.org/private/kbcez0wxhfvahimdtvu64g
>
> Basically I am trying to manipulate the contents of :name and then check
> to see if a record already exists - to save duplicates.
>
> --
> 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 [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.