Module: MizugumoLinkHelper
- Includes:
- ActionView::Helpers::UrlHelper
- Defined in:
- lib/mizugumo_link_helper.rb
Instance Method Summary collapse
- #degradable_form_for_link(*args, &block) ⇒ Object
-
#link_to(*args, &block) ⇒ Object
Redefined link_to to provide Mizugumo-style graceful degradation.
Instance Method Details
#degradable_form_for_link(*args, &block) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/mizugumo_link_helper.rb', line 27 def degradable_form_for_link(*args, &block) if block_given? return degradable_form_for_link(capture(&block), *args) else contents = args.shift if contents =~ /<img.+src=['"](\S+?)['"]/ submit_element = image_submit_tag($1) title = "block was passed" else title = contents submit_element = (title, :type => 'submit') end end = args[0] || {} = args[1] action = url_for() # debugger method = [:method] # debugger cssclass = [ 'mizugumo_graceful_form' ] cssclass << [:class] unless [:class].blank? = (, ) .merge!({:action => action, :method => :post, :title => title, :class => cssclass}) .delete('rel') .delete('class') content_tag(:form, ) do hidden_field_tag("_method", method) + hidden_field_tag("authenticity_token", session[:_csrf_token]) + submit_element end end |
#link_to(*args, &block) ⇒ Object
Redefined link_to to provide Mizugumo-style graceful degradation. If a :method option was provided, this replaces the link with a form and specifies a class so that MizugumoScript will convert it to the expected link on Javascript-enabled browsers.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/mizugumo_link_helper.rb', line 11 def link_to(*args, &block) if block_given? = args[0] || {} = args[1] else = args[1] || {} = args[2] end if and [:method] degradable_form_for_link(*args, &block) else super(*args, &block) end end |