Module: SimplyHelpful::RailsHelpers

Defined in:
lib/simply_helpful/rails_helpers.rb

Instance Method Summary collapse

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,options={})
	#	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 = options.delete(:alt) || options.delete('alt') || image
	tag('img',options.merge({:src => src, :alt => alt}))
end

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 button_link_to( title, url, options={} )
	classes = ['link']
	classes << options[:class]
	s =  "<a href='#{url_for(url)}' style='text-decoration:none;'>"
	s << "<button type='button'>"
	s << title
	s << "</button></a>\n"
end


37
38
39
40
41
42
# File 'lib/simply_helpful/rails_helpers.rb', line 37

def destroy_link_to( title, url, options={}, &block )
	s = form_link_to( title, url, options.merge(
		'method' => 'delete',
		:class => 'destroy_link_to'
	),&block )
end

#flasherObject



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 << ( :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


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, options={}, &block )
#			"action='#{url}' " <<
	extra_tags = extra_tags_for_form(options)
	s =  "\n" <<
		"<form " <<
		"class='#{options.delete(:class)||'form_link_to'}' " <<
		"action='#{url_for(url)}' " <<
		"method='#{options.delete('method')}'>\n" <<
		extra_tags << "\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

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 old_button_link_to( title, url, options={} )
#		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 << options[: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

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)
	html_options = if block_given?
		args[1] ||= {}
	else
		args[2] ||= {}
	end
	html_options.delete(:value)   #	possible key meant for submit button
	html_options.delete('value')  #	possible key meant for submit button
	( html_options[:class] ||= '' ) << ' submit button'
	link_to( *args, &block )
end