复选框参数提交但不插入

时间:2013-06-06 14:55:55

标签: ruby-on-rails

在我的Users表中,我有布尔列:owner,manager。 提交表单后,下面不会更新表格。

  <%= f.check_box :owner %> 
  <%= f.label :owner %>

日志:

Processing by UsersController#create as HTML


Parameters: {"utf8"=>"✓", "authenticity_token"=>"k0m814s9fRjCUZxeBXn5GO3o5Fq0evZG1Xc7IfUCOYU=", "user"=>{"name"=>"Bob Dylan", "email"=>"bob.dylan@gmail.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "manager"=>"0", "owner"=>"1"}, "commit"=>"Create my account"}
Unpermitted parameters: manager, owner
   (0.2ms)  begin transaction
  User Exists (0.3ms)  SELECT 1 AS one FROM "users" WHERE LOWER("users"."email") = LOWER('bob.dylan@gmail.com') LIMIT 1
Binary data inserted for `string` type on column `password_digest`
  SQL (56.3ms)  INSERT INTO "users" ("created_at", "email", "name", "password_digest", "remember_token", "updated_at") VALUES (?, ?, ?, ?, ?, ?)  [["created_at", Thu, 06 Jun 2013 14:57:53 UTC +00:00], ["email", "bob.dylan@gmail.com"], ["name", "Bob Dylan"], ["password_digest", "$2a$10$t5hux4e.jDWS9GH7fJj7Z.gSkLehpJxzfwXOTqbnL6LA7zWZT/11S"], ["remember_token", "J-OFaVfx3a4KMGQ0Q9vttg"], ["updated_at", Thu, 06 Jun 2013 14:57:53 UTC +00:00]]

3 个答案:

答案 0 :(得分:1)

在您的用户控制器中,您必须具有以下内容:

def user_params
  params.require(:user).permit(:manager, :owner)
end

答案 1 :(得分:0)

<label>Owner: </label><input type="checkbox" name="owner" value="1" />

如果选中该复选框,则所有者密钥将出现在post数组中。

要在提交表单后查看表单时选中复选框,您需要在复选框元素上添加checked="checked"作为属性。

答案 2 :(得分:0)

您需要进入视图并为该特定字段创建复选框或单选按钮。在您看来,您可以这样做:

form_for @user do |f|
  f.label :owner
  f.check_box :owner
  f.submit
end

您可以根据需要将其包装在html代码中。