1

I need to add the following attribute in my rails image_tag

data-zoom-image

I tried

<%= image_tag @post.uploads.first.upload.url(:medium), data: { :zoom-image => 'test'} %>

But throwing syntax error undefined local variable or method image.

How can I add attribute rails

1 Answer 1

4

:zoom-image isn't a valid symbol. You can't have a dash in there. You want this:

data: { zoom_image: 'test'}

or this:

data: { 'zoom-image' => 'test'}

In the both cases, Rails will output data-zoom-image="test" into the HTML.

Sign up to request clarification or add additional context in comments.

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.