How born an error studing a forum

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
@topic = Topic.new(params[:topic])
if @topic.save
@topic = Topic.new(:name => params[:topic][:name], :forum_id =>
params[:topic][:forum_id])

    if @post.save
    flash[:notice] = "Successfully created topic."
    redirect_to "/forums/#{@topic.forum_id}"
    else
    render :action => 'new'
    end
else
 render :action => 'new'
end

end
########

but when I create a topic on the webinterface of the app I receive the
following error message:

Showing /home/user/forum/app/views/topics/_form.html.erb where line #9
raised:

undefined method `content’ for :post:Symbol

Extracted source (around line #9):

6: <%= f.text_field :name %>
7:


8:


9: <%= f.text_area :post.content %><%= @post.content %>


10:

<%= f.submit “Create” %>


11: <% end %>

It’s a syntax error ? I’m converting an example app from a Rails 2 to
Rails 3

thanks,

C

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
@topic = Topic.new(params[:topic])
if @topic.save
@topic = Topic.new(:name => params[:topic][:name], :forum_id =>
params[:topic][:forum_id])
@post = Post.new(:content => params[:post][:content], :topic_id =>
Topic.first.id)
if @post.save
flash[:notice] = “Successfully created topic.”
redirect_to “/forums/#{@topic.forum_id}”
else
render :action => ‘new’
end
else
render :action => ‘new’
end
end
########

bye to me

C

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs