-
-
Save mkdynamic/2018727 to your computer and use it in GitHub Desktop.
Trying some different ways to secure a Rails application with user input
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
module ControllerFormAttributes | |
def self.included(base) | |
base.extend ClassMethods | |
end | |
module ClassMethods | |
def form_params_accessors(type, attributes = []) | |
@form_params_accessors ||= {} | |
@form_params_accessors[type] ||= attributes | |
end | |
end | |
def form_params_for(type) | |
type = type.to_sym | |
if current_user.try(:role_is?, 'admin') | |
return params[type] | |
else | |
return params[type].slice(*form_params_accessors(type)) | |
end | |
end | |
end | |
class ActionController::Base | |
include ControllerFormAttributes | |
end | |
# class UsersController < ApplicationController | |
# form_params_accessors :user, [:email, :password, :password_confirmation] | |
# | |
# def create | |
# @user = User.new(form_params_for(:user)) | |
# ... | |
# end | |
# end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment