0

This should be simple but I am stuck. I am trying to pass a value from erb to jQuery in a Rails app. There are two popups. One on page load and another on a button click. Both return undefined.

Also, is there a simpler form of the content_tag I can use for passing variables?

show.html.erb

<%= content_tag "div", id: "batch_status", data: {batch_status: @batch.status} do %><% end %>

rendered page html source

<div data-batch-status="completed" id="batch_status"></div>

batches.js.coffee

jQuery ->
  alert $('#batch_status').data('batch_status')

  $("#apply_btn").on "click", ->
    alert $('#batch_status').data('batch_status')

1 Answer 1

1

Try this:

<%= content_tag "div", id: "batch_status", 'data-batch_status' => @batch.status do %><% end %>
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.