0

In my Users table I have boolean columns: owner, manager. The below does not update the table once the form is submitted.

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

Logs:

Processing by UsersController#create as HTML


Parameters: {"utf8"=>"✓", "authenticity_token"=>"k0m814s9fRjCUZxeBXn5GO3o5Fq0evZG1Xc7IfUCOYU=", "user"=>{"name"=>"Bob Dylan", "email"=>"[email protected]", "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('[email protected]') 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", "[email protected]"], ["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
  • It's strange that it doesn't update the table, can you check the log and see which parameters are being passed? Commented Jun 6, 2013 at 15:09
  • It's in the parameters sent but its not in the INSERT... ??? Commented Jun 6, 2013 at 15:15
  • 1
    Yes, the problem was that you were not permitting those parameters. Commented Jun 6, 2013 at 15:30

3 Answers 3

1

In your User controller you must have something like:

def user_params
  params.require(:user).permit(:manager, :owner)
end
Sign up to request clarification or add additional context in comments.

Comments

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

The owner key will be present in the post array if the checkbox is checked.

To make the checkbox checked when viewing the form after the form is submitted, you need to add checked="checked" as an attribute on the checkbox element.

Comments

0

You will need to go into your view and create either a checkbox or a radio button for that particular field. In your view, you would do:

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

You would wrap this in the html code as needed.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.