2010-03-30 87 views
1

我第一次在项目中使用collection_select,并且我用它撞墙了。collection_select按预期工作

A个人资料has_one团队,团队has_many个人资料。

在我的编辑配置文件的视图中,我有这个。

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

其中按预期填充团队标题的下拉列表。我读过的几个例子似乎以非常相似的方式使用它。

我找不到配置文件何时保存,为什么它没有填充我的数据库中的team_id字段。在开发日志中,team_id正在被传递。

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"} 

更新控制器是标准支架一个,这对于所有其他补充我已经预先作出的剖面模型工作得很好。我错过了明显的东西吗?

编辑:用于更新操作

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] 
+1

还有什么是你的日志?这显示你看起来不错。有没有执行任何sql命令? – klew 2010-03-30 19:36:24

+0

任何特定日志?我已经用更新操作的完整日志/开发进行了更新 – Kelvin 2010-03-30 20:00:27

回答

2

完整的日志/ development.log试试这个:

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