Rails 4 - undefined method build in using strong parameters

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

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

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)