Module: Wallaby::FormHelper
- Included in:
- ResourcesHelper
- Defined in:
- lib/helpers/wallaby/form_helper.rb
Overview
Form helper
Instance Method Summary collapse
-
#hint_of(metadata) ⇒ String?
To fetch the hints from the following keys: - hints.#{ type }_html - hints.#{ type }.
-
#polymorphic_options(metadata, wildcard = 'QUERY', select_options = {}) ⇒ String
To generate dropdown options (class => url) for polymorphic class.
-
#remote_url(url, model_class, wildcard = 'QUERY') ⇒ String
To generate remote URL for auto select plugin.
Instance Method Details
#hint_of(metadata) ⇒ String?
To fetch the hints from the following keys:
-
hints.#{ type }_html
-
hints.#{ type }
45 46 47 48 49 50 51 52 53 |
# File 'lib/helpers/wallaby/form_helper.rb', line 45 def hint_of() type = [:type] hint = [:hint] # @see http://guides.rubyonrails.org/i18n.html#using-safe-html-translations hint ||= type && wt("hints.#{type}_html", default: [:"hints.#{type}", '']) return if hint.blank? content_tag :p, hint, class: 'help-block' end |
#polymorphic_options(metadata, wildcard = 'QUERY', select_options = {}) ⇒ String
To generate dropdown options (class => url) for polymorphic class. This function will pull out remote URLs from ‘metadata` (Class => url).
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/helpers/wallaby/form_helper.rb', line 29 def (, wildcard = 'QUERY', = {}) urls = [:remote_urls] || {} = ([:polymorphic_list] || []).map do |klass| [ klass, klass, { data: { url: remote_url(urls[klass], klass, wildcard) } } ] end , end |
#remote_url(url, model_class, wildcard = 'QUERY') ⇒ String
To generate remote URL for auto select plugin.
15 16 17 |
# File 'lib/helpers/wallaby/form_helper.rb', line 15 def remote_url(url, model_class, wildcard = 'QUERY') url || index_path(model_class, url_params: { q: wildcard, per: wallaby_controller.try(:page_size) }) end |