Unpermitted Parameters - Rails 4

303 views
Skip to first unread message

Rita Yahint

unread,
Apr 21, 2014, 6:46:32 PM4/21/14
to rubyonra...@googlegroups.com
Hi,
I'm using Devise (3.2.4), Rails 4 and I'm trying to signup.

I have a Registration Controller where i do have:

"
def sign_up_params
params.require(:user).permit(:email,:first_name,
:last_name,:mobile, :birthday, :current_password,
:password,:password_confirmation)
end
"

and everytime i try to sign up I get the following message:

Processing by Devise::RegistrationsController#create as HTML
Parameters: {"utf8"=>"✓",
"authenticity_token"=>"p9qVwZp/rDtJyvfV2TVdNXmh29JEoTs9SbyLHyNSq44=",
"user"=>{"first_name"=>"Joao", "last_name"=>"Miguel", "birthday"=>"",
"mobile"=>"0987654", "email"=>"joao....@gmail.com",
"password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"},
"commit"=>"Sign up"}
Unpermitted parameters: first_name, last_name, birthday, mobile

and my users table is updated but first_name, last_name, birthday,
mobile are null.

Does anyone has any idea how can I solve this issue?
thanks in advance

--
Posted via http://www.ruby-forum.com/.

Mateus Couto

unread,
Apr 21, 2014, 8:34:14 PM4/21/14
to rubyonra...@googlegroups.com
Hey there,

Have a look at this example
https://gist.github.com/bluemont/e304e65e7e15d77d3cb9
It should solve your problem.



Sent from my iPhone
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/3ab6f62b3fdb903d455095ac135a73d9%40ruby-forum.com.
> For more options, visit https://groups.google.com/d/optout.

Rita Yahint

unread,
Apr 22, 2014, 10:47:36 AM4/22/14
to rubyonra...@googlegroups.com
After update my Registration Controller, restart server, I still get the
same error.

Gustavo Caso

unread,
Apr 23, 2014, 5:28:43 AM4/23/14
to rubyonra...@googlegroups.com
You need to override the devise strong params implementation inside your ApplicationController.

We could use a simple before_filter to check if devise controller is been use.
```ruby
class ApplicationController < ActionController::Base
before_filter :configure_permitted_parameters, if: :devise_controller?

private
def configure_permitted_parameters
devise_parameter_sanitazer.for(:sign_up){|u| u.permit(:first_name, :last_name, :birthday, :mobile, :password, :password_confirmation}
end
end
´´´

Hope that helps.

Fernando Kakimoto

unread,
Apr 23, 2014, 8:14:16 AM4/23/14
to rubyonra...@googlegroups.com
Hi Rita, 

Please, check the following steps:

1. If you created a custom RegistrationController, you have to set devise routes to use it. Something like this:

<config/routes.rb>
devise_for :users, controllers: { registrations: "registrations" }

2.sign_up_params is a private method in devise source code. So make sure that your method definition is inside a private section of you custom controller as well.

private

def sign_up_params
  (...)
end

I've written a blog post describing how my team extended devise's RegistrationController here. Hope it helps.

Cheers,
Fernando 


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Rita Yahint

unread,
Apr 24, 2014, 6:21:40 AM4/24/14
to rubyonra...@googlegroups.com
It worked.
Thank you so much for your help :)

Pratap Patil

unread,
May 9, 2014, 1:00:06 AM5/9/14
to rubyonra...@googlegroups.com
Hi
 
 Acutly rails 4 support strong parameter , we need mention those attributes outside model such as nested attributes , needs declare in controller to_pramas private method

And more rails 4 strong parameter please check following link

http://pratap477.blogspot.in/2014/02/rails-4-strong-parameter.html
 
I think help u..
Reply all
Reply to author
Forward
0 new messages