1

I'm trying to make link_to function have a css class attached to it,

My code is something like this:

<%= link_to newGame do%>
<%= image_tag newGame.image_url.to_s %>
<% end %>

which links an image to its content, but I need to add a class="thumbnail" to the link,

ie:

<a href="/games/:id" class="thumbnaill>

instead of what its currently generating:

<a href="/games/:id">

Thanks

2 Answers 2

1

Ref link_to

<%= link_to newGame, class: 'thumbnail'  do %>

Be careful when using the older argument style, as an extra literal hash is needed:

<%= link_to "Articles", { :controller => "articles" }, :id => "news", :class => "article" %>
#Gives <a href="/articles" class="article" id="news">Articles</a>
Sign up to request clarification or add additional context in comments.

Comments

0

You can just do

<%= link_to newGame, class: 'thumbnail' do %>
  <%= image_tag newGame.image_url.to_s %>
<% end %>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.