Need help with Unpermitted Parameters for Devise | Rails 4

527 views
Skip to first unread message

David Williams

unread,
Dec 12, 2014, 7:18:57 PM12/12/14
to rubyonra...@googlegroups.com
Users\registrations_controller.rb



class User::RegistrationsController < Devise::RegistrationsController

before_filter :configure_permitted_parameters

protected
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) do |u| u.permit(:username,
:email, :age, :custommodel, :gender, :password, :password_confirmation)
end

devise_parameter_sanitizer.for(:account_update) do |u|
u.permit(:username, :email, :age, :custommodel, :gender, :password,
:password_confirmation, :current_password)
end
end
end



User.rb

class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
validates :email, :custommodel, :age, :gender, :presence => true
validates :username, presence: true, uniqueness: true
end



application_controller.rb

class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
before_action :configure_permitted_parameters, if: :devise_controller?

protected
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:custommodel1,
:custommodel2, :custommodel3, :custommodel4, :custommodel5,
:custommodel6, :phonenumber, :username)}
devise_parameter_sanitizer.for(:sign_up) {|u| u.permit(:username, :age,
:custommodel, :gender)}
devise_parameter_sanitizer.for(:account_update) {|u| u.permit(:username,
:custommodel1, :custommodel2, :custommodel3, :custommodel4,
:custommodel5, :custommodel6, :custommodel7, :custommodel8, :age,
:custommodel9, :gender)}
end
end



I've done just about everything I can't get these actions to go into the
db, but I continuously get Unpermitted parameters: email, password,
password_confirmation rollback transaction. What can I do to get these
models to conform with the Devise strong parameters?



Thank you again

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

Vivek Sampara

unread,
Dec 13, 2014, 2:02:36 AM12/13/14
to rubyonra...@googlegroups.com
Hi David, 

I think the parameters were not allowed into the registrations controller from the application controller in your case. Your application controller should look like this. 


class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
before_action :configure_permitted_parameters, if: :devise_controller?

protected
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:custommodel1,
:custommodel2, :custommodel3, :custommodel4, :custommodel5,
:custommodel6, :phonenumber, :username)}
devise_parameter_sanitizer.for(:sign_up) {|u| u.permit(:username, :age,
:custommodel, :gender, :email,, :password, :password_confirmation)}
--
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/6c960a11ce7b98b12a2e6e7d6d7cd330%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages