Skip to content

Instantly share code, notes, and snippets.

@danreedy
Forked from jamonholmgren/user_controller.rb
Last active December 26, 2015 08:49
Show Gist options
  • Save danreedy/7124928 to your computer and use it in GitHub Desktop.
Save danreedy/7124928 to your computer and use it in GitHub Desktop.
class UserController < ApplicationController
def create
@user = User.create(UserInput.create(params))
end
def update
@user = User.find(params[:id].to_i)
@user.update_attributes(UserInput.update(params))
end
def update_password
@user = User.find(params[:id].to_i)
@user.update_attributes(UserInput.update_password(params))
end
end
class UserInput
def initialize(p)
@params = p
end
class << self
def create(p)
p.require(:user).permit([ :name, :email, :password, :password_confirmation ])
end
def update(p)
p.require(:user).permit([ :name, :email ])
end
def update_password(p)
p.require(:user).permit([ :password, :password_confirmation ])
end
end
end
@danreedy
Copy link
Author

Just a quick update to the source pattern, completely untested but wanted to put it down while I was thinking about it.

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