Josh Hunter
Josh Hunter

Reputation: 1687

erb without rails helpers

I'm switching a python app to ruby and need to implement erb into the html and am clueless as to how to implement some of the most basic things. It seems like everything that I look up basically recommends using rails helpers that aren't available to me. I'm trying to get the below line to work. I figured anything in the loop would get interpolated, but my links aren't working. Any help would be much appreciated.

 <% for employee in @employees %>
        <div class="col-sm-6 col-md-3 employee">
            <a style="text-align:center;" href="/employee/#{employee.id}" class="thumbnail">
              <% if !employee.filename? %>  
              <img src='#{settings.employee_image_url}'> 
              <% else %>
              <img src='#{settings.no_image_url}'>
              <% end %>

Upvotes: 0

Views: 242

Answers (3)

Josh Hunter
Josh Hunter

Reputation: 1687

I moved the link and image tags into separate methods. That contain the strings. so..

def tag_string 
"<a style='text-align:center;' href='/employee/#{employee.id}' class='thumbnail'>"
end

and call it in the view like this:

<%= tag_string %>

Basically, all you have to do is make whatever tag you're interpolating into a string with double quotes and put the erb tags on either side. This is the answer I wish I would've found with googling.

Upvotes: 0

cll
cll

Reputation: 111

The follow should fix the issue.

<img src="<%= settings.no_image_url %>">

String Interpolation is only executed by Ruby, "#{settings.no_image_url}" is not a Ruby string in the context that you're using it.

Upvotes: 1

user2635088
user2635088

Reputation: 1618

Try using double quotes here '#{settings.employee_image_url}' instead of single quotes. So "#{settings.employee_image_url}"

Upvotes: 0

Related Questions