0
<script type="text/javascript">
  $(document).on("change","#status",function() {
    var id_booking = $(this).attr('class')
    data = $('option:selected',this).text().toLowerCase()
    $.ajax({
      type: "PATCH",
      url: "<%= room_booking_path(room_id: 1, id: 1, status: data) %>",
    })
  })

Error: undefined local variable or method `data' for #ActionView::Base:0x00000000017430

How can i pass "data" variable to <%= %> tag. Thank you!

lethetai
  • 1
  • 3
  • Relevant: [What is the difference between client-side and server-side programming?](https://stackoverflow.com/q/13840429) – VLAZ May 29 '22 at 11:14

1 Answers1

0

You try this way.

  <%= javascript_tag do %>
   $(document).on("change","#status",function() {
    var id_booking = $(this).attr('class')
    data = $('option:selected',this).text().toLowerCase()
    $.ajax({
      type: "PATCH",
      url: "<%= room_booking_path(room_id: 1, id: 1, status: data) %>",
    })
  })
  <% end %>
LihnNguyen
  • 632
  • 4
  • 10