Class: BaseEditingController
- Inherits:
-
RestrictedAreaController
- Object
- RestrictedAreaController
- BaseEditingController
- Defined in:
- app/controllers/base_editing_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
-
#default_distinct ⇒ Object
Configure default distinct results in the index query.
-
#default_sorts ⇒ Object
Configure default sort in the index query.
- #destroy ⇒ Object
-
#display_action_column ⇒ Object
Display action column in the index table.
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/controllers/base_editing_controller.rb', line 75 def create @object = base_class.new(permitted_attributes) @object = yield(@object) if block_given? # se è già stato autorizzano non rieseguiamo, utile nel caso vogliamo sovrascrivere la logica di autorizzazione in inheritance @object unless respond_to do |format| if @object.save _successful_create(format) else Rails.logger.debug { "#{base_class} non creato: #{@object.errors..inspect}" } _failed_create(format) end end end |
#default_distinct ⇒ Object
Configure default distinct results in the index query. Works like documented in activerecord-hackery.github.io/ransack/going-further/other-notes/#problem-with-distinct-selects
23 |
# File 'app/controllers/base_editing_controller.rb', line 23 class_attribute :default_distinct, default: true |
#default_sorts ⇒ Object
Configure default sort in the index query. Works like documented in activerecord-hackery.github.io/ransack/getting-started/sorting/#sorting-in-the-controller
18 |
# File 'app/controllers/base_editing_controller.rb', line 18 class_attribute :default_sorts, default: ["id"] |
#destroy ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 |
# File 'app/controllers/base_editing_controller.rb', line 91 def destroy @object = yield(@object) if block_given? respond_to do |format| if @object.destroy _successful_destroy(format) else _failed_destroy(format) end end end |
#display_action_column ⇒ Object
Display action column in the index table.
27 |
# File 'app/controllers/base_editing_controller.rb', line 27 class_attribute :display_action_column, default: true |
#edit ⇒ Object
55 56 57 |
# File 'app/controllers/base_editing_controller.rb', line 55 def edit @object = yield(@object) if block_given? end |
#index ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/controllers/base_editing_controller.rb', line 29 def index # se è già stato autorizzano non rieseguiamo, utile nel caso vogliamo sovrascrivere la logica di autorizzazione in inheritance base_class unless q = policy_scope(base_scope) @search_instance = search_class.new(q, current_user, params: params.permit(:page, :q => {}), # FIXME trovare modo per essere più "STRONG" sorts: default_sorts, distinct: default_distinct, display_action_column: display_action_column ) @search_instance = yield(@search_instance) if block_given? end |
#new ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/controllers/base_editing_controller.rb', line 43 def new @object = base_class.new @object = yield(@object) if block_given? # se è già stato autorizzano non rieseguiamo, utile nel caso vogliamo sovrascrivere la logica di autorizzazione in inheritance @object unless respond_to do |format| format.html end end |
#show ⇒ Object
59 60 61 |
# File 'app/controllers/base_editing_controller.rb', line 59 def show @object = yield(@object) if block_given? end |
#update ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/controllers/base_editing_controller.rb', line 63 def update @object = yield(@object) if block_given? respond_to do |format| if @object.update(permitted_attributes(@object)) _successful_update(format) else Rails.logger.debug { "#{base_class} non creato: #{@object.errors..inspect}" } _failed_update(format) end end end |