Forum: Ruby on Rails Problem with params[]

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
8a7a74182e801b31248d51cf8d94f2d5?d=identicon&s=25 rick_2047 (Guest)
on 2009-02-01 16:25
(Received via mailing list)
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....
978ed7ca309d5495078702096f9add03?d=identicon&s=25 Thomas r. Koll (tomk32)
on 2009-02-01 18:25
(Received via mailing list)
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
This topic is locked and can not be replied to.