Skip to content

Instantly share code, notes, and snippets.

@adammcarth
Created March 10, 2013 07:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adammcarth/5127559 to your computer and use it in GitHub Desktop.
Save adammcarth/5127559 to your computer and use it in GitHub Desktop.
If statement inside an image_tag
What I'm trying to achieve?
I want to have a left tooltip (tooltip-left) for the 2 results which display on the left hand side, and a right tooltip (tooltip-right) for the other 2 results which display on the right.
# Without tooltip customisation
<%= link_to image_tag(image.path, :alt => image.description), "/images/" + image.permalink.to_s, "data-toggle" => "tooltip-left", "data-original-title" => image.tooltip %>
# With tooltip customisation
<%= link_to image_tag(image.path, :alt => image.description), "/images/" + image.permalink.to_s, "data-toggle" => "#{if index == 0 or index == 2}tooltip-left#{else}tooltip-right#{end}", "data-original-title" => image.tooltip %>
# Error output:
# syntax error, unexpected '}', expecting keyword_then or ';' or '\n'
#
# Any ideas as to how I could approach this problem?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment