Module: Presenting::Helpers
- Defined in:
- lib/presenting/helpers.rb
Instance Method Summary collapse
- #present(*args, &block) ⇒ Object
-
#present_checkbox_search(field, options = {}) ⇒ Object
presents a checkbox search widget for the given field (a Presentation::FieldSearch::Field, probably).
-
#present_dropdown_search(field, options = {}) ⇒ Object
presents a dropdown/select search widget for the given field (a Presentation::FieldSearch::Field, probably).
-
#present_text_search(field, options = {}) ⇒ Object
presents a text search widget for the given field (a Presentation::FieldSearch::Field, probably).
Instance Method Details
#present(*args, &block) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/presenting/helpers.rb', line 3 def present(*args, &block) = args.length > 1 ? args. : {} if args.first.is_a? Symbol object, presentation = nil, args.first else object, presentation = args.first, args.second end if presentation klass = "Presentation::#{presentation.to_s.camelcase}".constantize rescue nil if klass instance = klass.new(, &block) instance.presentable = object instance.controller = controller instance.render elsif respond_to?(method_name = "present_#{presentation}", true) send(method_name, object, ) else raise ArgumentError, "unknown presentation `#{presentation}'" end elsif object.respond_to?(:loaded?) # AssociationProxy present_association(object, ) else present_by_class(object, ) end end |
#present_checkbox_search(field, options = {}) ⇒ Object
presents a checkbox search widget for the given field (a Presentation::FieldSearch::Field, probably)
38 39 40 41 |
# File 'lib/presenting/helpers.rb', line 38 def present_checkbox_search(field, = {}) current_value = (params[:search][field.param][:value] rescue nil) check_box_tag [:name], '1', current_value.to_s == '1' end |
#present_dropdown_search(field, options = {}) ⇒ Object
presents a dropdown/select search widget for the given field (a Presentation::FieldSearch::Field, probably)
44 45 46 47 |
# File 'lib/presenting/helpers.rb', line 44 def present_dropdown_search(field, = {}) current_value = (params[:search][field.param][:value] rescue nil) select_tag [:name], ((field.), current_value) end |
#present_text_search(field, options = {}) ⇒ Object
presents a text search widget for the given field (a Presentation::FieldSearch::Field, probably)
32 33 34 35 |
# File 'lib/presenting/helpers.rb', line 32 def present_text_search(field, = {}) current_value = (params[:search][field.param][:value] rescue nil) text_field_tag [:name], h(current_value) end |