Displaying 1 result from an estimated 1 matches for "present_tag".
2005 Dec 28
1
making has_and_belongs_to_many save more elegant
...st I also want to save all the tags
associated with it. I do that in the post_controller like this
presently:
def save
@post = Post.new(@params[:post])
@tags = Tag.new(@params[:tags])
@post.user_id = session[:id]
if @post.save
@tags.title.split('','').each do |tag|
present_tag = Tag.find_by_title(tag.strip)
present_tag = Tag.create(:title => tag.strip) if present_tag.nil?
@post.tags.push(present_tag)
end
flash[:notice] = "Successfully Created Post!"
redirect_to :controller => "home", :action => "index"
else...