RailsCasts Pro episodes are now free!
Learn more or hide this
GitHub User: thb
Site: tymate.com
Hi, I would write the create method like this:
def create @commentable = find_commentable instance_variable_set("@#{@commentable.class.to_s.downcase}", @commentable) comment = @commentable.comments.new(params[:comment]) if comment.save redirect_to @commentable, :notice => "Comment successfully created!" else render "#{@commentable.class.to_s.tableize}/show" end end
Hi, I would write the create method like this: