class ScaffoldPlus::Generators::AuthorityGenerator
Public Instance Methods
update_controller()
click to toggle source
# File lib/generators/scaffold_plus/authority/authority_generator.rb, line 38 def update_controller return unless options.controller? file = "app/controllers/#{table_name}_controller.rb" inject_into_file file, after: /before_action :set_#{name}.*$/ do "\n authorize_actions_for #{class_name}, only: [:index, :new, :create]" end inject_into_file file, after: /private$/ do "\n def authority_forbidden(error)" + "\n Authority.logger.warn(error.message)" + "\n redirect_to root_path, alert: 'Forbidden'" + "\n end\n" end inject_into_file file, after: /@#{name} = #{class_name}.find.*$/ do "\n authorize_action_for(@#{name})" end inject_into_file file, after: /@#{name} = #{class_name}.friendly.find.*$/ do "\n authorize_action_for(@#{name})" end end
update_model()
click to toggle source
# File lib/generators/scaffold_plus/authority/authority_generator.rb, line 19 def update_model inject_into_class "app/models/#{name}.rb", class_name do text = options.before? ? "\n" : "" text << " include Authority::Abilities\n" if options.authorizer.present? text << " self.authorizer_name = '#{options.authorizer}'\n" else text << " self.authorizer_name = '#{class_name}Authorizer'\n" end text << "\n" if options.after? text end end