Class: AgileFormFields::LinkTo
- Inherits:
-
AgileFormField
- Object
- AgileFormField
- AgileFormFields::LinkTo
- Defined in:
- app/models/agile_form_fields/link_to.rb
Overview
Implementation of link_to AgileRails form field. link_to form field is mostly used by polls but can be also incorporated anywhere on the form.
Form options:
-
type:
link_to (required) -
caption:
Link caption -
icon:
Link icon -
url:
direct url link -
controller:
controller name -
action:
action name -
html:
html options which apply to link_to (optional)
Form example:
30:
type: link_to
caption: Some action
icon: cogs
controller: my_controller
action: my_action
id: id # will be replaced by record.id
Instance Attribute Summary
Attributes inherited from AgileFormField
Instance Method Summary collapse
-
#render ⇒ Object
Render link_to AgileRails form field code.
Methods inherited from AgileFormField
get_data, #hash_to_options, #html, #initialize, #options_to_hash, #record_text_for, #ro_standard, #set_css_code, #set_default_value, #set_initial_value, #set_style, #t
Constructor Details
This class inherits a constructor from AgileFormFields::AgileFormField
Instance Method Details
#render ⇒ Object
Render link_to AgileRails form field code
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/models/agile_form_fields/link_to.rb', line 52 def render @yaml['html'] ||= {} @yaml['html']['class'] ||= 'ar-link' @yaml['html'].symbolize_keys! @yaml[:id] = record.id if @yaml[:id] == 'id' url = @yaml['url'] || "#{@yaml[:controller]}/#{@yaml[:action]}/#{@yaml[:id]}" url.gsub!('//','/') # no action and id url = '/' + @yaml['url'] unless url[0,1] == '/' # no leading / url.chop if url[0,-1] == '/' # remove trailing / caption = @yaml['caption'] || @yaml['text'] @html += @env.agile_link_to(caption, @yaml['icon'], url, @yaml['html']) self end |