kart-able
kart-able

Reputation: 106

Trying link_to image_tag

I want to turn an image into a link using Rails and have tried this:

link_to image_tag("rails.png", alt: "Rails logo"),
        'http://rubyonrails.org/

just like in the tutorial I am following https://www.railstutorial.org/book/ or this after looking in the api doc:

link_to(image_tag("rails.png", alt: "Rails logo"), "http://rubyonrails.org/")

but it won't work.

TypeError: Cet objet ne gère pas cette propriété ou cette méthode' which should mean the object doesn't deal with this method

Thanks for the help!

Same error with image_path (but image_alt works)

Upvotes: 0

Views: 2725

Answers (3)

vishnuprakash
vishnuprakash

Reputation: 51

link_to your_url do 
  image_tag("image_path")
end

Upvotes: 0

fool-dev
fool-dev

Reputation: 7777

I don't know but maybe the solution after refactoring this way like

Step 1 Remove these lines from your page like

link_to image_tag("rails.png", alt: "Rails logo"),
        'http://rubyonrails.org/
link_to(image_tag("rails.png", alt: "Rails logo"), "http://rubyonrails.org/")

and refresh again your page and see the working without any error? if so next

Step 2 Show the only image using image_tag like

<%= image_tag('rails.png', alt: "Rails logo") %>

and refresh again web page, the image showing properly without any error? if so next

Step 3 Apply link_to to the image_tag like

<%= link_to image_tag('rails.png', alt: "Rails logo"), 'http://rubyonrails.org/' %>

That's it, if any step is breaking with an error then refactor this step then go ahead.

This working on my hand.

Edit after comment

I believing your issue coming for other reason but I don't know what is this reason, I suggesting you go ahead with new course after skipping this issue.

For this issue, you can resolve this using HTML like

<a href="http://rubyonrails.org/">
    <img src="/assets/rails.png" alt="Rails logo">
</a>

Hope it helps

Upvotes: 3

Ruturaj Bisure
Ruturaj Bisure

Reputation: 159

link_to image_tag("rails.png", alt: "Rails logo"), 'http://rubyonrails.org/

May be your missing last closing '

Add ' in above and try. Or Try below line,

link_to image_tag("image_path"), "your_link_here"

Upvotes: 0

Related Questions