Created
October 23, 2013 19:06
-
-
Save jamonholmgren/7124659 to your computer and use it in GitHub Desktop.
Cleaner params
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 UserController < ApplicationController | |
def create | |
@user = User.create(UserInput.new(params).create) | |
end | |
def update | |
@user = User.find(params[:id].to_i) | |
@user.update_attributes(UserInput.new(params).update) | |
end | |
def update_password | |
@user = User.find(params[:id].to_i) | |
@user.update_attributes(UserInput.new(params).update_password) | |
end | |
end |
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 UserInput | |
def initialize(p) | |
@params = p | |
end | |
def create | |
@params.require(:user).permit([ :name, :email, :password, :password_confirmation ]) | |
end | |
def update | |
@params.require(:user).permit([ :name, :email ]) | |
end | |
def update_password | |
@params.require(:user).permit([ :password, :password_confirmation ]) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
:magic: