class ProgrammableScaffoldRails::ActionControllerHelpers
Used to avoid polluting controller class with methods
Public Class Methods
new(parent)
click to toggle source
# File lib/programmable_scaffold_rails/action_controller_helpers.rb, line 9 def initialize(parent) @parent = parent end
Public Instance Methods
after_create_action()
click to toggle source
# File lib/programmable_scaffold_rails/action_controller_helpers.rb, line 61 def after_create_action @after_create_action = options[:after_create_action].try(:to_sym) end
after_create_url(obj)
click to toggle source
# File lib/programmable_scaffold_rails/action_controller_helpers.rb, line 101 def after_create_url(obj) run_after_url_call_or_yield(:create, obj) { after_create_or_update_default_url(:create, obj) } end
after_destroy_url(obj)
click to toggle source
# File lib/programmable_scaffold_rails/action_controller_helpers.rb, line 109 def after_destroy_url(obj) run_after_url_call_or_yield(:destroy, obj) do if url_namespace.blank? controller.url_for(multiple_instances_name) else controller.url_for([url_namespace, multiple_instances_name]) end end end
after_update_action()
click to toggle source
# File lib/programmable_scaffold_rails/action_controller_helpers.rb, line 65 def after_update_action @after_update_action = options[:after_update_action].try(:to_sym) end
after_update_url(obj)
click to toggle source
# File lib/programmable_scaffold_rails/action_controller_helpers.rb, line 105 def after_update_url(obj) run_after_url_call_or_yield(:update, obj) { after_create_or_update_default_url(:create, obj) } end
call_strong_params()
click to toggle source
# File lib/programmable_scaffold_rails/action_controller_helpers.rb, line 94 def call_strong_params unless controller.respond_to?(strong_params) raise NotImplementedError, 'No strong_params method specified' end controller.send(strong_params) end
cancan()
click to toggle source
# File lib/programmable_scaffold_rails/action_controller_helpers.rb, line 27 def cancan return @cancan unless @cancan.nil? @cancan = !!options[:cancan] end
find_by_id_or_friendly_id(params)
click to toggle source
# File lib/programmable_scaffold_rails/action_controller_helpers.rb, line 79 def find_by_id_or_friendly_id(params) found = nil if friendly_id && klass.respond_to?(:friendly) found = klass.friendly.find(params[:id]) else found = klass.find(params[:id]) end found end
formats()
click to toggle source
# File lib/programmable_scaffold_rails/action_controller_helpers.rb, line 69 def formats @formats ||= options[:formats] end
friendly_id()
click to toggle source
# File lib/programmable_scaffold_rails/action_controller_helpers.rb, line 73 def friendly_id return @friendly_id unless @friendly_id.nil? @friendly_id = !!options[:friendly_id] end
klass()
click to toggle source
# File lib/programmable_scaffold_rails/action_controller_helpers.rb, line 13 def klass return @klass if @klass @klass = options[:class_name].try(:to_s) || controller.controller_name.to_s @klass = @klass.classify.constantize end
multiple_instances()
click to toggle source
# File lib/programmable_scaffold_rails/action_controller_helpers.rb, line 51 def multiple_instances @multiple_instances ||= "@#{ multiple_instances_name }".to_sym end
multiple_instances_name()
click to toggle source
# File lib/programmable_scaffold_rails/action_controller_helpers.rb, line 44 def multiple_instances_name return @multiple_instances_name if @multiple_instances_name @multiple_instances_name = options[:multiple_instances_name].try(:to_s) || table.to_s @multiple_instances_name = @multiple_instances_name.pluralize.to_sym end
single_instance()
click to toggle source
# File lib/programmable_scaffold_rails/action_controller_helpers.rb, line 40 def single_instance @single_instance ||= "@#{ single_instance_name }".to_sym end
single_instance_name()
click to toggle source
# File lib/programmable_scaffold_rails/action_controller_helpers.rb, line 33 def single_instance_name return @single_instance_name if @single_instance_name @single_instance_name = options[:single_instance_name].try(:to_s) || table.to_s @single_instance_name = @single_instance_name.singularize.to_sym end
strong_params()
click to toggle source
# File lib/programmable_scaffold_rails/action_controller_helpers.rb, line 90 def strong_params @strong_params ||= options[:strong_params].try(:to_sym) end
table()
click to toggle source
# File lib/programmable_scaffold_rails/action_controller_helpers.rb, line 20 def table return @table if @table @table = options[:table_name].try(:to_s) || klass.to_s @table = @table.tableize.to_sym end
url_namespace()
click to toggle source
# File lib/programmable_scaffold_rails/action_controller_helpers.rb, line 55 def url_namespace return @url_namespace if @url_namespace @url_namespace = options[:url_namespace].try(:to_s) || '' end
Protected Instance Methods
after_create_or_update_default_url(crud_action, obj)
click to toggle source
# File lib/programmable_scaffold_rails/action_controller_helpers.rb, line 121 def after_create_or_update_default_url(crud_action, obj) after_action = send(:"after_#{ crud_action }_action") if url_namespace.blank? if after_action.nil? || after_action == :show controller.url_for(obj) else # :edit controller.url_for([:edit, obj]) end else if after_action.nil? || after_action == :show controller.url_for([url_namespace, obj]) else # :edit controller.url_for([:edit, url_namespace, obj]) end end end
controller()
click to toggle source
# File lib/programmable_scaffold_rails/action_controller_helpers.rb, line 138 def controller @parent end
Private Instance Methods
options()
click to toggle source
# File lib/programmable_scaffold_rails/action_controller_helpers.rb, line 144 def options @parent.class.programmable_scaffold_options end
run_after_url_call_or_yield(crud_action, obj) { || ... }
click to toggle source
# File lib/programmable_scaffold_rails/action_controller_helpers.rb, line 148 def run_after_url_call_or_yield(crud_action, obj) after_url = options[:"after_#{ crud_action }_url"] if after_url.class <= Symbol controller.send(after_url, obj) elsif after_url.class <= Proc controller.instance_exec(obj, &after_url) elsif after_url.class <= String controller.url_for(after_url) else yield end end