Getting null value when it's assigned

I have my articles migration

create_table :articles do |t| t.integer :category_id, :null => false etc..

and my form

Select a category <%= :category_id, Category.all.collect {|category| [, ]} %>

But everytime im sending that info im getting a nil value for category_id

I'm assuming the problem happens when creating new records. Can we see the new and create actions in your controller and the full form in the view? Also, are there any before/after/around filters and/or callbacks that could be affecting the behavior of the application?

First look in development.log to see if it is being passed with the request ok. Then use ruby-debug to break into your code in the controller action (create or update presumably) and you can inspect the data to work out where it is getting lost. See the Rails Guide on debugging to find how to do that.


This could be that you are trying to assign attributes that are protected from mass assignment. Try adding:

attr_accessible :category_id your article model.