Topic: collection_select not being submitted database

Hi everybody,
I apologize for my student's english.

I got some problem with my Rails app, i got a collection_select who
aren't submited & save in my database. After 2 days googling and didn't
find anything helpful i'am asking your help.

I had two tables: Crc and User: (I removed useless relation from others

User model:

class User < ActiveRecord::Base
  has_many :crcs
  accepts_nested_attributes_for :crcs

  def role_symbols
     return ["#{}".to_sym]

Crc model:
class Crc < ActiveRecord::Base
  belongs_to :user
  attr_accessible :user_id

  validates_presence_of :name, :place
  validates_uniqueness_of :name

My views: (I removed user field form except username)

<% form_for @user do |f| %>
  <%= f.error_messages %>
        <%= f.label :username %><br />
        <%= f.text_field :username %>
         <%=  collection_select(:crc, :user_id, Crc.all, :id, :name) %>
  <p><%= f.submit %></p>
<% end %>

My logs:

Processing UsersController#create (for at 2010-07-26 12:20:29)
  Parameters: {"commit"=>"Save changes",
"user"=>{"password_confirmation"=>"pass", "role_id"=>"1",
"username"=>"usertest", "password"=>"pass", "email"=>""},

For me that seems good.

i got an User_Create acion:

User Create (0.3ms)   INSERT INTO `users` (`created_at`,
`crypted_password`, `updated_at`, `username`, `role_id`,
`password_salt`, `persistence_token`, `email`) VALUES('2010-07-26
'2010-07-26 10:20:29', 'usertest', 1, 'SCgvhFqM0E9R7rkxXPWY',

I didn't got Crc_Create action or any other Crc action. And my user_id
field still 'NULL' on database.

Thanks for reading, I hope is clear.


Last edited by harks (2010-07-26 06:52:37)

Re: collection_select not being submitted database

Just try to do the same operation in rails console:

user= User.create(put your attributes here as hash)

and you'll see if CRS array is empty