kndwsu
kndwsu

Reputation: 381

how to add jquery data attributes in rails image_tag

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

Upvotes: 1

Views: 1520

Answers (1)

Philip Hallstrom
Philip Hallstrom

Reputation: 19899

: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.

Upvotes: 4

Related Questions