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
tables)
User model:
class User < ActiveRecord::Base
has_many :crcs
accepts_nested_attributes_for :crcs
acts_as_authentic
def role_symbols
return ["#{self.role.name}".to_sym]
end
end
Crc model:
class Crc < ActiveRecord::Base
belongs_to :user
attr_accessible :user_id
validates_presence_of :name, :place
validates_uniqueness_of :name
end
My views: (I removed user field form except username)
<% form_for @user do |f| %>
<%= f.error_messages %>
<%= f.label :username %>
<%= f.text_field :username %>
<%= collection_select(:crc, :user_id, Crc.all, :id, :name) %>
<%= f.submit %>
<% end %>My logs:
Processing UsersController#create (for 127.0.0.1 at 2010-07-26 12:20:29)
[POST]
Parameters: {“commit”=>“Save changes”,
“authenticity_token”=>“6qJ/pJVcDVvNeaACnyOKRKT2R6EIA7TWVfvlMXxRMkk=”,
“user”=>{“password_confirmation”=>“pass”, “role_id”=>“1”,
“username”=>“usertest”, “password”=>“pass”, “email”=>“[email protected]”},
“crc”=>{“user_id”=>“2”}}
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
10:20:29’,
‘b693ef04a548e3006ac8d81534717b46d7cb6146dd60e5f0e253d88356798431a5accabb135ee4727a68b9b9692e4245ab10ef9455fdbcfb44ffc88b5b402897’,
‘2010-07-26 10:20:29’, ‘usertest’, 1, ‘SCgvhFqM0E9R7rkxXPWY’,
‘26260bc8aa988fc3895af5b6cfcc5778b0872ce21aaa6924ac38f6c185293b457edb81d95a2ee3d5d7b78ea76a3229e6da68e6102c258861e857a769e784f2a5’,
‘[email protected]’)
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.
Loic/Harks