ruby on rails - Shows image path rather then the image, within one-line if..else statement -


i have following line of code:

<%= "brand: " + (@user.activated ? "image_tag('brand1.png', class: 'branding')" : "image_tag('brand2.png', class: 'branding')") + "(#{@user.activated_at})" %> 

it should show (where image shown depends on whether user activated):

brand: {image} 6-19-2015

instead of image, displays literal image path (so text). how should adjust code show actual image instead?

that's weird way write erb template code. @mudasobwa says have quotes around image tags wrong, , adding lots of strings in erb tag messy, fragile , unreadable. 2 image tags identical dried well.

i think trying so:

<% graphic =  @user.activated ? "brand1.png" : "brand2.png" %> brand: <%= image_tag(graphic, class: 'branding') %> (<%= @user.activated_at %>) 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -