Sha256: 05103f343c6577cd4b889b3fec6bda7ea782b3667de11ca88c579f289792b88c

Contents?: true

Size: 1.74 KB

Versions: 97

Compression:

Stored size: 1.74 KB

Contents

module ActiveScaffold
  module Helpers
    module ControllerHelpers
      def self.included(controller)
        controller.class_eval { helper_method :params_for, :main_path_to_return }
      end
      
      include ActiveScaffold::Helpers::IdHelpers
      
      def params_for(options = {})
        # :adapter and :position are one-use rendering arguments. they should not propagate.
        # :sort, :sort_direction, and :page are arguments that stored in the session. they need not propagate.
        # and wow. no we don't want to propagate :record.
        # :commit is a special rails variable for form buttons
        blacklist = [:adapter, :position, :sort, :sort_direction, :page, :record, :commit, :_method, :authenticity_token]
        unless @params_for
          @params_for = params.clone.delete_if { |key, value| blacklist.include? key.to_sym if key }
          @params_for[:controller] = '/' + @params_for[:controller] unless @params_for[:controller].first(1) == '/' # for namespaced controllers
          @params_for.delete(:id) if @params_for[:id].nil?
        end
        @params_for.merge(options)
      end

      # Parameters to generate url to the main page (override if the ActiveScaffold is used as a component on another controllers page)
      def main_path_to_return
        parameters = params.clone
        if params[:parent_controller]
          parameters[:controller] = params[:parent_controller]
          parameters[:eid] = params[:parent_controller]
        end
        parameters[:nested] = nil
        parameters[:parent_model] = nil
        parameters[:parent_column] = nil
        parameters[:parent_id] = nil
        parameters[:action] = "index"
        parameters[:id] = nil
        params_for(parameters)
      end
    end
  end
end

Version data entries

97 entries across 97 versions & 2 rubygems

Version Path
six-updater-web-0.24.15 lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/controller_helpers.rb
six-updater-web-0.24.14 lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/controller_helpers.rb
six-updater-web-0.24.13 lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/controller_helpers.rb
six-updater-web-0.24.12 lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/controller_helpers.rb
six-updater-web-0.24.11 lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/controller_helpers.rb
six-updater-web-0.24.10 lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/controller_helpers.rb
six-updater-web-0.24.9 lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/controller_helpers.rb
six-updater-web-0.24.8 lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/controller_helpers.rb
six-updater-web-0.24.7 lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/controller_helpers.rb
six-updater-web-0.24.6 lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/controller_helpers.rb
six-updater-web-0.24.5 lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/controller_helpers.rb
six-updater-web-0.24.4 lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/controller_helpers.rb
six-updater-web-0.24.3 lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/controller_helpers.rb
six-updater-web-0.24.2 lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/controller_helpers.rb
six-updater-web-0.24.1 lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/controller_helpers.rb
six-updater-web-0.24.0 lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/controller_helpers.rb
six-updater-web-0.23.7 lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/controller_helpers.rb
six-updater-web-0.23.6 lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/controller_helpers.rb
six-updater-web-0.23.5 lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/controller_helpers.rb
six-updater-web-0.23.4 lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/controller_helpers.rb