Last active
February 10, 2016 15:12
-
-
Save LolWalid/b041f2785e369d2af016 to your computer and use it in GitHub Desktop.
Strong parameters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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