0

我在数据库中创建了一个枚举字段。现在我想将字段绑定到视图,使其显示所有可用值以供选择。在这种情况下男性和女性。

t.enum  :sex ,:limit => [:Male, :Female]

编辑:

SQL generated:
Started PUT "/profiles/3" for 127.0.0.1 at 2012-06-04 22:11:35 -0700
Processing by ProfilesController#update as HTML
  Parameters: {"utf8"=>"?", "authenticity_token"=>"IJGsa4RfVeBC/LwD6PI69rJ5O0RxmPNTu7PavqK5hPM=", "profile"=>{"firstname"=>"Huzaifa ", "sex"=>"Female"}, "commit"=>"Update Profile", "id"=>"3"}
  [1m[36mProfile Load (1.0ms)[0m  [1mEXEC sp_executesql N'SELECT TOP (1) [profiles].* FROM [profiles] WHERE [profiles].[id] = @0', N'@0 int', @0 = 3[0m  [["id", "3"]]
  [1m[35mSQL (0.0ms)[0m  BEGIN TRANSACTION
  [1m[36mCACHE (0.0ms)[0m  [1mSELECT @@TRANCOUNT[0m
  [1m[35mSQL (0.0ms)[0m  COMMIT TRANSACTION
Redirected to http://localhost:3000/profiles/3
Completed 302 Found in 5ms (ActiveRecord: 2.0ms)        
4

2 回答 2

1

可以在表单中以多种方式呈现一系列值,但听起来您想要一个选择字段。我假设您的列名是“枚举”

= form_for @<model_name> |t| 
  = t.select :enum, [:Male, :Female]
于 2012-06-05T02:53:04.953 回答
0

没有传递价值,

 <%= f.select :sex , [[ "Male" ,0] , ["Female" , 3 ]] %>
于 2012-06-05T05:35:51.263 回答