SitePoint Sponsor |
|
User Tag List
Results 1 to 12 of 12
Thread: Email tag and image problem
-
Mar 7, 2006, 21:06 #1
- Join Date
- Nov 2004
- Location
- Victoria BC
- Posts
- 116
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Email tag and image problem
How do you show an email image with an address attached to it. I have tried numerous mail_to and image_tag variations but just can't seem to figure it out. Does anyone have the solution to this problem?
Rick
-
Mar 8, 2006, 10:13 #2
- Join Date
- Feb 2003
- Location
- Mexico City
- Posts
- 122
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Code:link_to image_tag(parameters...), 'mailto:someone@somewhere.com'
-
Mar 8, 2006, 12:33 #3
- Join Date
- Nov 2004
- Location
- Victoria BC
- Posts
- 116
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Ivan,
Thanks for that, so simple yet so difficult at the same time. Syntax is the big problem here and getting used to it.
Rick
-
Mar 8, 2006, 12:50 #4
- Join Date
- Feb 2003
- Location
- Mexico City
- Posts
- 122
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I feel your pain
But rest assured you'll get up to speed fast enough, and then there's no turning back.
Code:<%= link_to image_tag("emailButton"), "mailto:#{list_stripes.email}" %>
image_tag("emailButton") translates to this: <img src="emailButton.png" />
The first parameter to link_to, would be what goes between <a href...> and </a>, and the second parameter is the actual href. So, it outputs this (obviosly with the correct values):
<a href="mailto:whatever is the value of list_stripes.email">here goes the output of the image_tag function (a helper actually)</a>
Also, if you don't know what #{..} is for inside a double quoted string ("..."), it works by replacing that brackets along with anything inside them with the value of the ruby expression inside, in this case, the value of list_stripes.email
I hope this helps you better understand how it all works.
Ivan V.
-
Mar 8, 2006, 13:06 #5
- Join Date
- Aug 2005
- Posts
- 986
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
If you are a PHP programmer, #{var} is the same as $var in PHP in a string:
$var = "a string";
$one = "this is $var";
$two = 'this is $var';
Now, $one is "this is a string", and $two is "this is $var" because the variable substitution doesn't exist in single-quoted strings.
This is the same in Ruby:
var = "a string"
one = "this is #{var}"
two = 'this is #{var}'
But you can put "real" code in it too:
three = "two is #{two.kind_of?(String) ? 'a string' : 'not a string'}"
three will be: "two is a string".
I hope this is not confusing you :P.
-
Mar 8, 2006, 15:02 #6
- Join Date
- Nov 2004
- Location
- Victoria BC
- Posts
- 116
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Let me thank you both for those excellent examples and descriptions. I am awaiting the book but in the meantime I am trying to forge on. I have one more relatively simple question. Let's say a returned field is null or blank. Is there an easy way to test for that condition. I am using
Code:<% if list_stripes.email != '' %>
Code:<% if list_stripes.email.nil? %>
Rick
-
Mar 9, 2006, 09:11 #7
- Join Date
- Feb 2003
- Location
- Mexico City
- Posts
- 122
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
You can use both:
Code:<% if list_stripes.email.nil? || list_stripes.email.empty? %>
-
Mar 10, 2006, 06:59 #8
- Join Date
- Aug 2005
- Posts
- 986
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
No, just use object.blank?
Code:>> [].blank? => true >> [1, 2, 3].blank? => false >> "".blank? => true >> 0.blank? => false >> nil.blank? => true
-
Mar 10, 2006, 10:00 #9
- Join Date
- Feb 2003
- Location
- Mexico City
- Posts
- 122
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Nice, I didn't know about those two.
-
Mar 10, 2006, 10:05 #10
- Join Date
- Nov 2004
- Location
- Victoria BC
- Posts
- 116
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks for that info. Where is it documented in the API docs?
Rick
-
Mar 10, 2006, 11:17 #11
Originally Posted by Fenrir2
-
Mar 10, 2006, 13:36 #12
- Join Date
- Aug 2005
- Posts
- 986
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
It's not in the Ruby documentation, it works only if you use Rails.
They've nodoc'd the method:
Code:class Object #:nodoc: # "", " ", nil, [], and {} are blank def blank? if respond_to?(:empty?) && respond_to?(:strip) empty? or strip.empty? elsif respond_to?(:empty?) empty? else !self end end end class NilClass #:nodoc: def blank? true end end class FalseClass #:nodoc: def blank? true end end class TrueClass #:nodoc: def blank? false end end class Array #:nodoc: alias_method :blank?, :empty? end class Hash #:nodoc: alias_method :blank?, :empty? end class String #:nodoc: def blank? empty? || strip.empty? end end class Numeric #:nodoc: def blank? false end end
Maybe it's intended for internal use only? I don't remember how I learned that this method exists...
Bookmarks