Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 802
LearningRoR Avatar asked Jun 29 '12 14:06

LearningRoR


1 Answers

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" %>
like image 111
Sully Avatar answered Sep 17 '22 13:09

Sully