0

I have a do statement in my view and was wondering how to format the code properly to use a class like other elements?

<%= link_to something_path do %>
  <div>Stuff</div>
<% end %>

I tried to do it like most ERB, adding the class to the end of the statement:

<%= link_to something_path do, class: "classname" %>

That didn't work so I tried to do it like an image_tag:

<%= link_to(something_path do, class: "classname") %>

Where does class: fit into this line of code?

2 Answers 2

1

Try the following.

<%= link_to(something_path, class: "classname") do %>
  <div>Stuff</div>
<% end %>
Sign up to request clarification or add additional context in comments.

Comments

1

Check out the documentation for link_to

It also has this example,

link_to "Articles", articles_path, id: "news", class: "article"
# => <a href="/articles" class="article" id="news">Articles</a>

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.