0

I have a Rails application where I try to write code into an string:

<% @diagnoses.each do |f| %>
  <a href="#" data-dropdown="drop#{f.id}" class=" tiny button dropdown expand">"#{f.beschreibung}"</a><br>

But somehow the "drop#{f.id}" and the "#{f.beschreibung}" are not written as a variable. What am I doing wrong and why?

3 Answers 3

5

you are most probably in an erb template so you have to do the following

<a href="#" data-dropdown="drop<%= f.id %>" class="tiny button dropdown expand">
  <%= f.beschreibung %>
</a>
Sign up to request clarification or add additional context in comments.

2 Comments

Edited out the double quotes. Don't think he wants them ;-)
@Mischa no worries. thanks! just wondering though. would making the file go through a ruby interpreter work as well? ie add a .rb extension? have you tried that?
2

If you're writing this in a view, you need to use <%= %> and make sure the file has the .erb extension

you code should be

<a href="#" data-dropdown="drop<%= f.id %>" class=" tiny button dropdown expand">"<%= f.beschreibung %>"</a><br>

Comments

0

You are missing <%= %>. However, I'd use the link_to helper:

<% @diagnoses.each do |f| %>
  <%= link_to f.beschreibung, "#", data: {dropdown: "drop#{1}"}, class: "tiny button dropdown expand" %>
<% 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.