pass javascript variable to erb code for checking condition

            def edit
                @course = Course.includes(holes:


   <%= form_for (@course), remote: true do |cb| %>

          <%= cb.text_field :course_name, class: “name" %>

          <div id="holes">
              <% (cb.object.holes).each do |i| %>
                <a href=“#" id="hole-<%= %>" class="holeid"
value="<%= %>"><%= %> </a>
                <div class="circular circle-green circle-left"></div>
              <% end %>

      <%= cb.fields_for :holes do |hb| %>
          <% if ( == ( %>

           <h3> <%= "#{} - #{} " %></h3>

            <%= hb.fields_for :beacons do |bb| %>
                    <div class=“tip"> <%= bb.label :CaddyTip %></div>
                     <div class=“ctip"> <%= bb.text_area :caddy_tip

                      <div class=“shot"> <%= bb.label :BestShot %></div>
                      <div class=“bshot"> <%= bb.text_area :best_shot

                     <div class=“be"> <%= bb.label :Be_Aware %></div>
                      <div class=“beaware"> <%= bb.text_area :be_aware

           <% end %>#beacons form close

        <% end %> #if close

      <% end %> # holes form close
  <% end %>#course form close

     var selected = [];
     var clickedholeid = $(".holeid").on('click', function(e) {

I want to pass user clicked hole-id to check if condition to display it
beacons within the page.My app is about Golf course game.
In this a course have 18 holes and each hole have 3
beacons(tip,approach,beaware) respectively. I alert user clicked hole id
in console but now i want to pass that value to if condition after holes
form in above code. Without that condition its display all 18 holes
beacons in edit page.(18 * 3)
So I need to stop that and default it display douse first hole beacons
after that if user perform click


If you want to evaluate a *client-side* variable value using Ruby on
the server you'll have to send it via AJAX. Otherwise include logic
in your JavaScript so the client can handle the checking.

function holeid(){
  type: "POST",
  url: "course/edit/",
  data: "Hole data="+ id,
  success: function(id){
    alert("Hole ID:"+ id );

Take a look at this gem:

Ryan Bates also did a Railscast about it.

I would advise you to pay the $9…he’s not charging recurring thereafter…it’s worth it… some of the info has not changed