Sha256: 57726edfadc64771153407b0ee9072ab4eb7f66eec3606a95eb0aff8b2be9623
Contents?: true
Size: 1.83 KB
Versions: 16
Compression:
Stored size: 1.83 KB
Contents
module Admix class InheritedController < Admix::AdmixController helper :all inherit_resources include InheritedResources::DSL rescue_from ActiveRecord::DeleteRestrictionError do |exception| #resource.errors.add(:base, exception) flash[:alert] = I18n.t('errors.dependent') redirect_to collection_url end # TODO: Add authorization here. before_filter :load_grid , only: [:index ] # Add a breadcrumb, in this case nested resources. ;) before_filter -> { if defined?(parent_type) breadcrumbs.add t("#{parent_type.to_s.gsub('_', '').pluralize}.#{parent_type.to_s.gsub('_', '').pluralize}") , polymorphic_path([:admix, parent_class]) breadcrumbs.add "#{parent.name}" , parent_url end } before_filter -> { breadcrumbs.add t("#{collection_name}.#{collection_name}"), collection_url, :i18n => false } before_filter -> { breadcrumbs.add "#{crumb_field}" , resource_url, :i18n => false } , except: [:index, :new, :create ] before_filter -> { breadcrumbs.add t("admix.crud.new.title"), :i18n => false } , only: [:new ] before_filter -> { @crumb_field = crumb_field } , only: [:edit ] protected def crumb_field field_name = if resource.respond_to?(:name) :name elsif resource.respond_to?(:title) :title elsif resource.respond_to?(:email) :email else raise "Implement crumb_field method in #{self}" end resource[field_name] end def load_grid @grid = initialize_grid(resource_class) end def collection_name @collection_name = resource_class.to_s.underscore.pluralize.gsub("::", "_") end def resource_name resource_class.to_s.downcase end def form_fields raise "TODO: We need implement this in #{self}" end end end
Version data entries
16 entries across 16 versions & 2 rubygems