Forum: Ruby on Rails Question: image_tag(source, options = {})

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F28f75d17a0c236e079c6ebbb8fff2b9?d=identicon&s=25 Mark Haliday (markh)
on 2005-12-16 04:24
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.
132a94ca65959bda6c74fae54bff2425?d=identicon&s=25 Ezra Zygmuntowicz (Guest)
on 2005-12-16 07:21
(Received via mailing list)
On Dec 15, 2005, at 7:24 PM, Mark Haliday wrote:

> neglected.
>
> Thanks for any help on this.
>
> --
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> 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 Zygmuntowicz
WebMaster
Yakima Herald-Republic Newspaper
ezra@yakima-herald.com
509-577-7732
2dd904ec5981c31e7bb7a5743a53caf8?d=identicon&s=25 Bruce Balmer (brucebalmer)
on 2005-12-16 07:33
(Received via mailing list)
<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
132a94ca65959bda6c74fae54bff2425?d=identicon&s=25 Ezra Zygmuntowicz (Guest)
on 2005-12-16 08:48
(Received via mailing list)
On Dec 15, 2005, at 8:59 PM, Ezra Zygmuntowicz wrote:

>>
>> Rails@lists.rubyonrails.org
>> 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 Zygmuntowicz
WebMaster
Yakima Herald-Republic Newspaper
ezra@yakima-herald.com
509-577-7732
F73b3bc57c492b0f9f3785968c69805e?d=identicon&s=25 karthik mani (karthikeyanm3)
on 2012-12-17 07:55
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 : <img alt="logo" src="logo.png" align="right"
style="background-color:#288AC6; padding:10px;" class="classname"
id="idname" />

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
52f3528c40e9cf28ad0900886eecb128?d=identicon&s=25 Jordon Bedwell (Guest)
on 2012-12-17 08:03
(Received via mailing list)
On Mon, Dec 17, 2012 at 12:55 AM, karthikeyan manivasagam
<lists@ruby-forum.com> 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.
This topic is locked and can not be replied to.