Created
March 31, 2014 16:12
-
-
Save davinmsu/9895906 to your computer and use it in GitHub Desktop.
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 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