0

So, I'm trying to get CanCan working but I'm having trouble with making an user an Admin. In other-words, I have a Users table with an admin:boolean column.

Now the problem is when I sign-up to my app and check off the Admin check box it doesn't register the Admin Boolean as True in the db. It remains nil.

I've followed the api.rails syntax for admin check box's but it doesn't seem to be changing the boolean value in the DB.

For a full scope of the app goto: www.github.com/apane/leap

Apane101
  • 1,121
  • 1
  • 14
  • 37

1 Answers1

1

As you are using Rails 4, you are using strong-parameters. And if you don't do anything about it, the admin checkbox will be taken out of your params during sign-up.

Your solution is to create your own controller for registration and to overwrite the params.permit method

I answer a similar question few days ago, you got my answer there: Rails 4.0 with Devise. Nested attributes Unpermited parameters

Community
  • 1
  • 1
Benjamin Bouchet
  • 12,971
  • 2
  • 41
  • 73
  • thanks, i made the registrations controller and inputted the data you listed but i'm not sure about the second part e.g. "def sign_up_params params.require(resource_name).permit! end" where does that go? – Apane101 Jul 23 '13 at 03:23
  • you don't use it, read carefully the answer: this part is just needed during tests. What you just have to use is the first block of code for the `class RegistrationsController`, and replace :your_fields by the fields you need (ex: `:admin`) – Benjamin Bouchet Jul 23 '13 at 03:31
  • Benjamin, thanks pal! I've followed your instructions however, I must be doing something wrong as the admin boolean is still nil. I've updated my github for you with your code www.github.com/apane/leap. Please advise :) – Apane101 Jul 23 '13 at 04:33
  • 1
    Hmm.. you did not read everything :) I mentioned "You must replace :your_fields by the fields you want to allow". you need to do that – Benjamin Bouchet Jul 23 '13 at 04:46