# How born an error studing a forum

**URL:** <https://discuss.rubyonrails.org/t/how-born-an-error-studing-a-forum/57986>\
**Category:** rubyonrails-talk\
**Created:** [March 18, 2011, 11:51pm UTC](https://discuss.rubyonrails.org/t/how-born-an-error-studing-a-forum/57986 "2011-03-18T23:51:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [March 18, 2011, 11:51pm UTC](https://discuss.rubyonrails.org/t/how-born-an-error-studing-a-forum/57986/1 "2011-03-18T23:51:26Z")

</div>

I'm studing a forum and when I create a Topic I have a \_form.html.erb relative a file inside follow directory

#app/views

new.html.erb \_form.html.erb .... ....

the snippet controller to create a new topic is the follow

#app/controllers/topics\_controller.rb

def create &nbsp;&nbsp;&nbsp;&nbsp;@topic = Topic.new(params[:topic]) &nbsp;&nbsp;&nbsp;&nbsp;if @topic.save &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@topic = Topic.new(:name =\> params[:topic][:name], :forum\_id =\> params[:topic][:forum\_id])

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if @post.save &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;flash[:notice] = "Successfully created topic." &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;redirect\_to "/forums/#{@topic.forum\_id}" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;render :action =\> 'new' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;else &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;render :action =\> 'new' &nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;end

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [March 19, 2011, 12:29am UTC](https://discuss.rubyonrails.org/t/how-born-an-error-studing-a-forum/57986/2 "2011-03-19T00:29:32Z")

</div>

No need create only 2 simple line in the follow file

#app/controllers/topics\_controllers

def new

@topic = Topic.new @post = Post.new

end

def create def create &nbsp;&nbsp;&nbsp;&nbsp;@topic = Topic.new(params[:topic]) &nbsp;&nbsp;&nbsp;&nbsp;if @topic.save &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@topic = Topic.new(:name =\> params[:topic][:name], :forum\_id =\> params[:topic][:forum\_id]) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@post = Post.new(:content =\> params[:post][:content], :topic\_id =\> Topic.first.id) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if @post.save &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;flash[:notice] = "Successfully created topic." &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;redirect\_to "/forums/#{@topic.forum\_id}" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;render :action =\> 'new' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;else &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;render :action =\> 'new' &nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;end
