Erwin1
(Erwin)
1
In my backoffice/users_controller.rb , I wrote a class to build the permitted parameters
class Backoffice::UsersController < ApplicationController
class UserParams
def build params
params.require(:user).permit(:email, :password, :password_confirmation )
end
end
but using it in the create method,
def create
@user = User.new(UserParams.build(params))
I get an error :
undefined method `build’ for Backoffice::UsersController::UserParams:Class
I guess I am wrong somewhere as the class is defined in the Backoffice module… where I am wrong ?
thanks for help
Colin_Law1
(Colin Law)
2
In my backoffice/users_controller.rb , I wrote a class to build the
permitted parameters
class Backoffice::UsersController < ApplicationController
class UserParams
def build params
If you want a class method (rather than instance) this should be
def self.build( params )
params.require(:user).permit(:email, :password,
:password_confirmation )
end
end
but using it in the create method,
def create
@user = User.new(UserParams.build(params))
I get an error :
undefined method `build' for Backoffice::UsersController::UserParams:Class
Because you have defined an instance method not a class method
Colin
Erwin1
(Erwin)
3
Thanks Colin… changed to :
private
def user_params
params.require(:user).permit(:email, :password, :password_confirmation )
end
and cretae /update…
def create
@user = User.new(user_params)