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
<%= f.select :category_id, Category.all.collect {|category|
[category.name, category.id ]} %>

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?

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

attr_accessible :category_id

…to your article model.

On 11 May 2011 01:19, Tomas R. [email protected] wrote:

[category.name, category.id ]} %>

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

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.

Colin

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