开发者

collection_select not working as expected

First time I've come to use collection_select in a project and I've hit a wall with it.

A Profile has_one Team, Team has_many Profile.

In my view for editing profiles I have this.

<td><%= f.collection_select(:team_id, @team, :id, :title) %>&l开发者_如何学JAVAt;/td>

Which populates the drop down with titles of teams as expected. The couple of examples I have read seem to use it in a very similar way.

I can't figure out when the profile is saved why it isn't populating the team_id field in my DB. In the development log the team_id is being passed.

Processing ProfilesController#update (for 127.0.0.1 at 2010-03-28 22:49:16) [PUT] Parameters: {"commit"=>"Update", "profile"=>{"dob(1i)"=>"2010", "second_name"=>"", "dob(2i)"=>"3", "role"=>"", "dob(3i)"=>"28", "project"=>"", "specialties"=>"", "about"=>"", "team_id"=>"1", "status"=>"", "first_name"=>""}, "authenticity_token"=>"sdTiFPGj9JCO3OEge5EGNGxZbQSsq9ME5LP342EBjyc=", "id"=>"3"}

The update controller is the standard scaffold one, this has worked fine for all other additions to the profile model I'd made previously. Am I missing something obvious?

EDIT: Full log/development.log for update action

Processing UsersController#edit (for 127.0.0.1 at 2010-03-30 20:41:52) [GET] Parameters: {"id"=>"3"}
  User Load (5.3ms)   SELECT * FROM "users" WHERE ("users"."id" = 3) LIMIT 1
  Profile Load (2.0ms)   SELECT * FROM "profiles" WHERE (user_id = 3) LIMIT 1
  Team Load (6.9ms)   SELECT * FROM "teams" 
Rendering template within layouts/main
Rendering users/edit
Completed in 143ms (View: 53, DB: 14) | 200 OK [http://localhost/users/3/edit]


Processing ProfilesController#update (for 127.0.0.1 at 2010-03-30 20:42:00) [PUT] Parameters: {"commit"=>"Update", "profile"=>{"dob(1i)"=>"2010", "second_name"=>"", "dob(2i)"=>"3", "role"=>"", "dob(3i)"=>"28", "project"=>"", "specialties"=>"", "about"=>"", "team_id"=>"1", "status"=>"", "first_name"=>""}, "authenticity_token"=>"m6klUObst8uSATwkei5nY6ISx4OCHHCr9lDRYD5+mrc=", "id"=>"3"}
  User Load (2.0ms)   SELECT * FROM "users" WHERE ("users"."id" = 3) LIMIT 1
  Profile Load (2.2ms)   SELECT * FROM "profiles" WHERE ("profiles"."id" = 3) 
  Profile Update (39.6ms)   UPDATE "profiles" SET "updated_at" = '2010-03-30 19:42:00', "team_id" = 1 WHERE "id" = 3
[paperclip] Saving attachments.
Redirected to http://localhost:3000/users/3
Completed in 359ms (DB: 44) | 302 Found [http://localhost/profiles/3]


Processing UsersController#show (for 127.0.0.1 at 2010-03-30 20:42:00) [GET] Parameters: {"id"=>"3"}
  User Load (1.5ms)   SELECT * FROM "users" WHERE ("users"."id" = 3) LIMIT 1
  Profile Load (2.2ms)   SELECT * FROM "profiles" WHERE (user_id = '3') LIMIT 1
Rendering template within layouts/main
Rendering users/show
  Team Load (1.0ms)   SELECT * FROM "teams" WHERE ("teams"."id" = 1) 
Completed in 115ms (View: 66, DB: 5) | 200 OK [http://localhost/users/3]


try this:

<%= f.collection_select(:profile, :team_id, @team, :id, :title) %>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜