Module: SimplyHelpful::RailsHelpers
- Defined in:
- lib/simply_helpful/rails_helpers.rb
Instance Method Summary collapse
- #aws_image_tag(image, options = {}) ⇒ Object
-
#button_link_to(title, url, options = {}) ⇒ Object
This style somehow for some reason actually submits the request TWICE? In many cases, this is no big deal, but when using it to send emails or something, the controller/action is called twice resulting in 2 emails (if that’s what your action does) I’d really like to understand why.
- #destroy_link_to(title, url, options = {}, &block) ⇒ Object
- #flasher ⇒ Object
- #form_link_to(title, url, options = {}, &block) ⇒ Object
- #javascripts(*args) ⇒ Object
-
#old_button_link_to(title, url, options = {}) ⇒ Object
This creates a button that looks like a submit button but is just a javascript controlled link.
-
#stylesheets(*args) ⇒ Object
Created to stop multiple entries of same stylesheet.
-
#submit_link_to(*args, &block) ⇒ Object
Just add the classes ‘submit’ and ‘button’ for styling and function.
Instance Method Details
#aws_image_tag(image, options = {}) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/simply_helpful/rails_helpers.rb', line 44 def aws_image_tag(image,={}) # in console @controller is nil protocol = @controller.try(:request).try(:protocol) || 'http://' host = 's3.amazonaws.com/' bucket = ( defined?(RAILS_APP_NAME) && RAILS_APP_NAME ) || 'ccls' src = "#{protocol}#{host}#{bucket}/images/#{image}" alt = .delete(:alt) || .delete('alt') || image tag('img',.merge({:src => src, :alt => alt})) end |
#button_link_to(title, url, options = {}) ⇒ Object
This style somehow for some reason actually submits the request TWICE? In many cases, this is no big deal, but when using it to send emails or something, the controller/action is called twice resulting in 2 emails (if that’s what your action does) I’d really like to understand why.
59 60 61 62 63 64 65 66 |
# File 'lib/simply_helpful/rails_helpers.rb', line 59 def ( title, url, ={} ) classes = ['link'] classes << [:class] s = "<a href='#{url_for(url)}' style='text-decoration:none;'>" s << "<button type='button'>" s << title s << "</button></a>\n" end |
#destroy_link_to(title, url, options = {}, &block) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/simply_helpful/rails_helpers.rb', line 37 def destroy_link_to( title, url, ={}, &block ) s = form_link_to( title, url, .merge( 'method' => 'delete', :class => 'destroy_link_to' ),&block ) end |
#flasher ⇒ Object
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/simply_helpful/rails_helpers.rb', line 90 def flasher s = '' flash.each do |key, msg| s << content_tag( :p, msg, :id => key, :class => 'flash' ) s << "\n" end s << "<noscript><p id='noscript' class='flash'>\n" s << "Javascript is required for this site to be fully functional.\n" s << "</p></noscript>\n" end |
#form_link_to(title, url, options = {}, &block) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/simply_helpful/rails_helpers.rb', line 18 def form_link_to( title, url, ={}, &block ) # "action='#{url}' " << = () s = "\n" << "<form " << "class='#{.delete(:class)||'form_link_to'}' " << "action='#{url_for(url)}' " << "method='#{.delete('method')}'>\n" << << "\n" s << (( block_given? )? capture(&block) : '') s << submit_tag(title, :name => nil ) << "\n" << "</form>\n" if block_called_from_erb?(block) concat(s) else s end end |
#javascripts(*args) ⇒ Object
112 113 114 115 116 117 118 119 120 |
# File 'lib/simply_helpful/rails_helpers.rb', line 112 def javascripts(*args) @javascripts ||= [] args.each do |javascript| unless @javascripts.include?(javascript.to_s) @javascripts.push(javascript.to_s) content_for(:head,javascript_include_tag(javascript).to_s) end end end |
#old_button_link_to(title, url, options = {}) ⇒ Object
This creates a button that looks like a submit button but is just a javascript controlled link. I don’t like it.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/simply_helpful/rails_helpers.rb', line 71 def ( title, url, ={} ) # id = "id='#{options[:id]}'" unless options[:id].blank? # klass = if options[:class].blank? # "class='link'" # else # "class='#{options[:class]}'" # end # s = "<button #{id} #{klass} type='button'>" classes = ['link'] classes << [:class] s = "<button class='#{classes.flatten.join(' ')}' type='button'>" s << "<span class='href' style='display:none;'>" s << url_for(url) s << "</span>" s << title s << "</button>" s end |
#stylesheets(*args) ⇒ Object
Created to stop multiple entries of same stylesheet
102 103 104 105 106 107 108 109 110 |
# File 'lib/simply_helpful/rails_helpers.rb', line 102 def stylesheets(*args) @stylesheets ||= [] args.each do |stylesheet| unless @stylesheets.include?(stylesheet.to_s) @stylesheets.push(stylesheet.to_s) content_for(:head,stylesheet_link_tag(stylesheet.to_s)) end end end |
#submit_link_to(*args, &block) ⇒ Object
Just add the classes ‘submit’ and ‘button’ for styling and function
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/simply_helpful/rails_helpers.rb', line 5 def submit_link_to(*args,&block) = if block_given? args[1] ||= {} else args[2] ||= {} end .delete(:value) # possible key meant for submit button .delete('value') # possible key meant for submit button ( [:class] ||= '' ) << ' submit button' link_to( *args, &block ) end |