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)
def hashtag(name)
string = name
return name = string if string.split.count <= 1
name = string.split.map{|w| w.capitalize}.join
end
def create
name = params[:topic][:name]
visible = params[:topic][:visible]
hashtag(name)
@topic = {:name => "#{name}", :visible => visible}
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.