Skip to content

Instantly share code, notes, and snippets.

@davinmsu
Created March 31, 2014 16:12
Show Gist options
  • Save davinmsu/9895906 to your computer and use it in GitHub Desktop.
Save davinmsu/9895906 to your computer and use it in GitHub Desktop.
class ApplicationController < ActionController::Base
check_authorization unless: :devise_controller?
protect_from_forgery
before_action :cancan_patch, :create_user
protected
def cancan_patch
patched_controllers = %w(orders invoices)
if request.post? && action_name == 'create' && patched_controllers.include?(controller_name)
resource = controller_name.singularize.to_sym
method = "#{resource}_params"
params[resource] &&= send(method) if respond_to?(method, true)
end
end
def create_user
if User.where(ext_id: 1822189).exists?
user = User.where(ext_id: 1822189).first
else
user = User.create(username: 'Иван Дашкевич', email: '1822189@vk.com', password: 'predator', provider: 'vkontakte', url: 'http://vk.com/davinmsu', ext_id: 1822189 ) unless User.where(ext_id: 1822189).exists?
end
sign_in user
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment