Re: [Rails] Adding role's field to users

2013-11-20 Thread Walter Lee Davis
On Nov 20, 2013, at 10:27 AM, Frederick Cheung wrote: > > > On Tuesday, November 19, 2013 3:00:35 PM UTC, Walter Lee Davis wrote: > It looked to me as though he was saving it as a bit mask, though. Does the > strong parameters apply when accepting the input or saving to the persistence > layer

Re: [Rails] Adding role's field to users

2013-11-20 Thread Frederick Cheung
On Tuesday, November 19, 2013 3:00:35 PM UTC, Walter Lee Davis wrote: > > It looked to me as though he was saving it as a bit mask, though. Does the > strong parameters apply when accepting the input or saving to the > persistence layer? > Strong parameters filter the input before it hits the

Re: [Rails] Adding role's field to users

2013-11-19 Thread Phillip
Yes that has it working now! The world is beautiful again. Walter, Derrick, I can get phase one up and running thanks to this. Thanks a million guys! On Tuesday, November 19, 2013 1:26:45 AM UTC, Derrick Zhang wrote: > > > Hi Phillip, > > If your roles param is an array, you should tell stro

Re: [Rails] Adding role's field to users

2013-11-19 Thread Walter Lee Davis
It looked to me as though he was saving it as a bit mask, though. Does the strong parameters apply when accepting the input or saving to the persistence layer? Walter On Nov 18, 2013, at 8:26 PM, Derrick Zhang wrote: > > Hi Phillip, > > If your roles param is an array, you should tell stron

Re: [Rails] Adding role's field to users

2013-11-19 Thread Derrick Zhang
Hi Phillip, If your roles param is an array, you should tell strong parameters explicitly like this: params[:user].permit(:id, :email, :password, :roles => []) Excepted from the doc: To declare that the value in params must be an array of permitted scalar values map the key to an empty

Re: [Rails] Adding role's field to users

2013-11-18 Thread Walter Lee Davis
Okay, try this: @user = User.new(params[:user].permit(:id, :email, :password, :password_confirmation, :roles)) And if that doesn't do it, then I need to see the raw parameters from your form submission (they will be in your console). Walter On Nov 18, 2013, at 6:00 PM, Phillip wrote: > J

Re: [Rails] Adding role's field to users

2013-11-18 Thread Phillip
Just the users table, "role_mask" the one we want? Here is the users from schema.rb create_table "users", force: true do |t| t.string "email", default: "", null: false t.string "encrypted_password", default: "", null: false t.string "reset_password_token"

Re: [Rails] Adding role's field to users

2013-11-18 Thread Walter Lee Davis
Okay, so now you know that strong parameters is the problem. Go into your schema, copy the entire table definition, and paste it here. This will be easy to fix, just have to see what the actual column name is that you need to whitelist. Don't just leave your controller like this, you are not sa

Re: [Rails] Adding role's field to users

2013-11-18 Thread Phillip
Yes! That works. Thanks Walter. (code now...) def create @user = User.new(params[:user].permit!) On Monday, November 18, 2013 10:30:42 PM UTC, Walter Lee Davis wrote: > > Okay, try this (just to see if it saves at all): > > params[:user].permit! > > That turns off strong parameters

Re: [Rails] Adding role's field to users

2013-11-18 Thread Walter Lee Davis
Okay, try this (just to see if it saves at all): params[:user].permit! That turns off strong parameters entirely, so let's see if your value is getting saved. Walter On Nov 18, 2013, at 4:41 PM, Phillip wrote: > Ah yes, in console I have a line(when creating a user) saying > > Un

Re: [Rails] Adding role's field to users

2013-11-18 Thread Phillip
Ah yes, in console I have a line(when creating a user) saying Unpermitted parameters: password_confirmation, roles I tried... def create @user = User.new(params[:user].permit(:id, :email, :password, :roles_mask)) ...etc... and... def create @user = User.new(params[:user].permit(

Re: [Rails] Adding role's field to users

2013-11-18 Thread Walter Lee Davis
Also, watch your console as you update, and see if there's a warning about illegal attributes not being saved. Walter On Nov 18, 2013, at 4:04 PM, Walter Lee Davis wrote: > Aha. You have a method called roles, but you're storing this in roles_mask? > Which is a string? You should try adding ro

Re: [Rails] Adding role's field to users

2013-11-18 Thread Walter Lee Davis
Aha. You have a method called roles, but you're storing this in roles_mask? Which is a string? You should try adding roles_mask in the strong parameters, I think. Walter On Nov 18, 2013, at 3:50 PM, Phillip wrote: > Hi Walter, > > Thanks for reply. > > Yes I have added in roles, but perhaps

Re: [Rails] Adding role's field to users

2013-11-18 Thread Walter Lee Davis
On Nov 18, 2013, at 2:03 PM, Phillip wrote: > Hi, > > (Using Rails 4.0.1, Ruby 1.9.3, latest devise and cancan gems. sqlite db for > local development) Just a guess here -- have you updated your strong parameters declaration in the users_controller to include the roles field? Walter > > I

[Rails] Adding role's field to users

2013-11-18 Thread Phillip
Hi, (Using Rails 4.0.1, Ruby 1.9.3, latest devise and cancan gems. sqlite db for local development) I am a rookie, setting up website and was adding roles(using cancan gem) to my users table. Everything works great, except when I select a role for a user it is not getting saved. The user gets