LearningRoR
LearningRoR

Reputation: 27192

How to pass html for a link_to block?

I'm trying to pass a link_to block with html but can't get it. I tried some other ways with no luck so I will use my original code:

<% link_to survey_path(survey), :class => "button" do %>
   <span>add questions to <%= survey.name %></span>
<% end %>

This doesn't show the :class though.

What needs to be corrected?

Upvotes: 12

Views: 12696

Answers (1)

Sully
Sully

Reputation: 14943

Try to add = to make it <%= %>

<%= link_to survey_path(survey), :class => "button" do %>
   <span>add questions to <%= survey.name %></span>
<% end %>

In the view code in Rails 3 applications it’s sometimes necessary to use <%= instead of <% at the beginning of blocks that output content, such as form_for.

Since it's just a span, why don't you just do

<%= link_to "add questions to #{survey.name}", survey_path(survey), :class => "button" %>

Upvotes: 35

Related Questions