Question: image_tag(source, options = {})


#1

image_tag(source, options = {})

Ok, when I want to use an image I added the following code:

<%= image_tag “dsf.jpg” options = {[align=“right”, style=“padding-right:
10px; padding-top: 5px;”]} %>

However, this doesn’t seem to work, it doesn’t like how I have the
“options” part setup. I’m sure there is something very easy I
neglected.

Thanks for any help on this.


#2

On Dec 15, 2005, at 7:24 PM, Mark H. wrote:

neglected.

Thanks for any help on this.


Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails

You need to loose the array inside your options hash I believe:

<%= image_tag “dsf.jpg” options = {align=“right”, style=“padding-
right: 10px; padding-top: 5px;”} %>

Cheers-
-Ezra Z.
WebMaster
Yakima Herald-Republic Newspaper
removed_email_address@domain.invalid
509-577-7732


#3

<newbie warning (I am being self referencing here)>

I believe that you should replace ‘the options=’ with a comma, you
don’t need the curly braces despite them using them in the
documentation and if options had been something you would use, it
would have been a symbol ie :options and then it would be => rather
than =

Other than that, I am not sure that you can put align=“right” in an
image. I think it would have to be outside the image. In any case,
I’d use css as it is the morally right thing to do (I believe it
saves trees) and so your line might end up looking like this:

%=image_tag(“dsf.jpg”, :class=>‘my_image_class’)

</newbie warning>
bruce


#4

On Dec 15, 2005, at 8:59 PM, Ezra Z. wrote:

removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails

You need to loose the array inside your options hash I believe:

<%= image_tag “dsf.jpg” options = {align=“right”, style=“padding-
right: 10px; padding-top: 5px;”} %>

Actually thats wrong, try this instead:

<%= image_tag “dsf.jpg”, :options =>
{:align=>“right”, :style=>“padding-right: 10px; padding-top: 5px;”} %>

Cheers-

-Ezra Z.
WebMaster
Yakima Herald-Republic Newspaper
removed_email_address@domain.invalid
509-577-7732


#5

Use the options directly in image tag as how you use in html tag,but
little convertion has to be done for Rails code, it will work

HTML : logo

RAILS : <%= image_tag(‘logo.png’, :alt=>‘logo’,:align=>‘right’
,:style=>‘background-color:#288AC6; padding:10px;’ ,:class=>‘classname’
, :id=>‘idname’) %>

Just make the attribute name in HTML as symbols followed by a value
as a key value pair

align = “left” HTML
:align => “left” RAILS

-Karthikeyan
Railsfactory


#6

On Mon, Dec 17, 2012 at 12:55 AM, karthikeyan manivasagam
removed_email_address@domain.invalid wrote:

Just make the attribute name in HTML as symbols followed by a value
as a key value pair

align = “left” HTML
:align => “left” RAILS

I just want to point out that you should not be using align, it’s not
supported in HTML5 because you can use css (read: float) and I also
want to point out that if you are just going to make your ALT the same
as your src minus extension you might as well not bother and let the
spec fail, I wish the engine were smart enough to detect people gaming
the system like that. Your desc should actually be a description or
don’t bother, you just take the piss out of the desc attribute and
what it’s used for in the current example.