Problem with params[]

I’m building a discussion forum in my rails app and there seems to be
a problem in creating a new topic in the forum.
I’m using three models for it forum, topic and post.
The topic model has following fields:
t.integer :forum_id
t.integer :user_id
t.string :name
t.datetime :created_at
t.datetime :updated_at
t.integer :posts_count,:null => false, :default => 0

the problem comes when i try to create a new topic in a forum. The
controller has following code:
def create

@topic = => params[:topic][:name], :forum_id =>

params[:forum_id], :user_id =>!

@post = => params[:post][:body],
                 :topic_id =>,
                 :user_id =>!

respond_to do |format|
 format.html { redirect_to posts_path(:topic_id =>

@topic, :forum_id => }
format.xml { head :created, :location => topic_path(:id =>
@topic, :forum_id => }
rescue ActiveRecord::RecordInvalid
respond_to do |format|
format.html { render :action => ‘new’ }
format.xml { render :xml => @post.errors.to_xml }

Now when the row is inserted into the topics table the forum_id field
is blank. I cant figure out what’s happening here. Please help…

Hi Rick,

Do you have validations in you models?
I mean like
validates_presence_of :forum_id

Besides that, I’d do a instead of

And third, please do a @forum = Forum.find(params[:forum_id])

And fourth, maybe its params[:topic][:forum_id] ??

ciao, tom