Module: MundaneSearch::ViewHelpers
- Defined in:
- lib/mundane-search/view_helpers.rb
Instance Method Summary collapse
- #search_form_default_options ⇒ Object
- #search_form_for(record, options = {}, &block) ⇒ Object
- #search_link_for(content, search, change_params = {}) ⇒ Object
- #search_url_for(search, change_params = {}) ⇒ Object
- #simple_search_form_for(record, options = {}, &block) ⇒ Object
-
#will_merge_change_hash?(a, b) ⇒ Boolean
should this be private?.
Instance Method Details
#search_form_default_options ⇒ Object
38 39 40 41 42 |
# File 'lib/mundane-search/view_helpers.rb', line 38 def { method: "GET" } end |
#search_form_for(record, options = {}, &block) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/mundane-search/view_helpers.rb', line 23 def search_form_for(record, = {}, &block) # Later! # if block_given? # form_for(record, search_form_default_options(record).merge(options), &block) # else # # Auto-generate form # end form_for(record.to_model, .merge(), &block) end |
#search_link_for(content, search, change_params = {}) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/mundane-search/view_helpers.rb', line 11 def search_link_for(content, search, change_params = {}) search_model = search.to_model link_to content, search_url_for(search, change_params), class: will_merge_change_hash?(search_model.params, change_params) ? nil : "unchanged-search" end |
#search_url_for(search, change_params = {}) ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/mundane-search/view_helpers.rb', line 3 def search_url_for(search, change_params = {}) search_model = search.to_model new_model_params = search_model.params.merge(change_params).reject {|k,v| v.nil? } new_params = Hash.new new_params[search_model.class.model_name.i18n_key] = new_model_params polymorphic_url search_model, new_params end |
#simple_search_form_for(record, options = {}, &block) ⇒ Object
33 34 35 36 |
# File 'lib/mundane-search/view_helpers.rb', line 33 def simple_search_form_for(record, = {}, &block) # TODO: warn if simple_form not available? simple_form_for(record.to_model, .merge(), &block) end |
#will_merge_change_hash?(a, b) ⇒ Boolean
should this be private?
19 20 21 |
# File 'lib/mundane-search/view_helpers.rb', line 19 def will_merge_change_hash?(a,b) !(a.merge(b) == a) end |