Skip to content

Instantly share code, notes, and snippets.

@jamonholmgren
Created October 23, 2013 19:06
Show Gist options
  • Save jamonholmgren/7124659 to your computer and use it in GitHub Desktop.
Save jamonholmgren/7124659 to your computer and use it in GitHub Desktop.
Cleaner params
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
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
@silasjmatson
Copy link

:magic:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment