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
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/controllers/base_editing_controller.rb', line 67 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.messages.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
20 |
# File 'app/controllers/base_editing_controller.rb', line 20 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
15 |
# File 'app/controllers/base_editing_controller.rb', line 15 class_attribute :default_sorts, default: ["id"] |
#destroy ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 |
# File 'app/controllers/base_editing_controller.rb', line 83 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 |
#edit ⇒ Object
47 48 49 |
# File 'app/controllers/base_editing_controller.rb', line 47 def edit @object = yield(@object) if block_given? end |
#index ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/controllers/base_editing_controller.rb', line 22 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 ) @search_instance = yield(@search_instance) if block_given? end |
#new ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/controllers/base_editing_controller.rb', line 35 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
51 52 53 |
# File 'app/controllers/base_editing_controller.rb', line 51 def show @object = yield(@object) if block_given? end |
#update ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/controllers/base_editing_controller.rb', line 55 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.messages.inspect}" } _failed_update(format) end end end |