Sha256: 9ce2caa1e690292efaf3730cdb7054dae371ce25764e054b42f206ac2bba32f5

Contents?: true

Size: 1.4 KB

Versions: 2

Compression:

Stored size: 1.4 KB

Contents

class <%= controller_class_name %>Controller < InheritedResources::Base
  
<% if actions -%>
  actions <%= symbol_array_to_expression(actions) %>
<% end -%>
<% if formats -%>
  respond_to <%= symbol_array_to_expression(formats) %>
  
<% end -%>
<% if actions -%>
  before_filter :load_resource, :only => [<%= symbol_array_to_expression(actions & DryScaffoldGenerator::DEFAULT_MEMBER_AUTOLOAD_ACTIONS) %>]
<% end -%>
<% if actions -%>
  before_filter :load_and_paginate_resources, :only => [<%= symbol_array_to_expression(actions & DryScaffoldGenerator::DEFAULT_COLLECTION_AUTOLOAD_ACTIONS) %>]
  
<% end -%>

<% (actions - DryScaffoldGenerator::DEFAULT_CONTROLLER_ACTIONS).each do |action| -%>
  # GET /<%= plural_name %>/<%= action.to_s %>
  def <%= action.to_s %>
    
  end
  
<% end -%>
  protected
    
    def collection
<% if options[:pagination] -%>
      paginate_options ||= {}
      paginate_options[:page] ||= (params[:page] || 1)
      paginate_options[:per_page] ||= (params[:per_page] || 20)
      @collection = @<%= model_plural_name %> ||= end_of_association_chain.paginate(paginate_options)
<% else -%>
      @collection = @<%= model_plural_name %> ||= end_of_association_chain.all
<% end -%>
    end
    alias :load_and_paginate_resources :collection
    
    def resource
      @resource = @<%= model_singular_name %> ||= end_of_association_chain.find(params[:id])
    end
    alias :load_resource :resource
    
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
grimen-dry_scaffold-0.3.0 generators/dry_scaffold/templates/controllers/inherited_resources_controller.rb
grimen-dry_scaffold-0.3.1 generators/dry_scaffold/templates/controllers/inherited_resources_controller.rb