Skip to content

Instantly share code, notes, and snippets.

@LolWalid
Last active February 10, 2016 15:12
Show Gist options
  • Save LolWalid/b041f2785e369d2af016 to your computer and use it in GitHub Desktop.
Save LolWalid/b041f2785e369d2af016 to your computer and use it in GitHub Desktop.
Strong parameters
class UsersController < ApplicationController
def create
@user = User.new(user_params)
# blablabla
end
private
def user_params
params.require(:user).permit(:user_id, :username, :name, :password)
end
end
class User
class << self
def custom_create(params)
create(permitted_parameters(params))
# blablabla
end
private
def permitted_parameters(params)
params = params.symbolize_keys
params[:user_id] = params[:id]
params.extract!(
:user_id,
:username,
:name,
:password
)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment