Class: Refine::StoredFiltersController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Refine::StoredFiltersController
- Defined in:
- app/controllers/refine/stored_filters_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/controllers/refine/stored_filters_controller.rb', line 36 def create @refine_filter = @refine_filter_builder.refine_filter @stored_filter = StoredFilter.new(name: params[:name], state: @refine_filter.state, filter_type: @refine_filter.type, **instance_exec(&Refine::Rails.configuration.custom_stored_filter_attributes)) @refine_filter_query = @refine_filter_builder.query if !@refine_filter_query.valid? # replace the filter form with errors render :create elsif !@stored_filter.save # replace the stored filter form render :new, status: :unprocessable_entity else # return to stored filters header and load the filter into the query builder @refine_filter_builder.stored_filter_id = @stored_filter.id render :find end end |
#find ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/controllers/refine/stored_filters_controller.rb', line 12 def find @stored_filter = StoredFilter.find_by(id: params[:id]) @refine_filter_builder.stored_filter_id = @stored_filter.id # KLUDGE we need a base scope for determining if the filter is valid. # We set initial_queryto model.all because this filter is used just for validation # and is never evaluated. # # This method is a temporary workaround until we clean up input validation and # filter evaluation filter_for_model = @stored_filter.refine_filter model = filter_for_model.model # AR::Base subclass @refine_filter = @stored_filter.refine_filter(initial_query: model.all) @refine_filter_query = Refine::Filters::Query.new(@refine_filter) unless @refine_filter.valid_query? redirect_to refine_stored_filters_path(@refine_filter_builder.to_params), alert: "Sorry, that filter is not valid" end end |
#index ⇒ Object
7 8 9 10 |
# File 'app/controllers/refine/stored_filters_controller.rb', line 7 def index @stored_filters = StoredFilter.where(filter_type: @refine_filter_builder.filter_class) @stored_filters = instance_exec(@stored_filters, &Refine::Rails.configuration.stored_filter_scope) end |
#new ⇒ Object
32 33 34 |
# File 'app/controllers/refine/stored_filters_controller.rb', line 32 def new @stored_filter = StoredFilter.new(filter_type: @refine_filter_builder.filter_class) end |