Rails 3;如果DB标志为true,则仅运行coffeescript

时间:2015-05-21 13:47:25

标签: ruby-on-rails coffeescript

我认为我有以下内容:

event.html.erb

 <%- if(@event.requires_registration?) -%>
          <div class="form-group registration_form">
            <%= form_tag(register_learner_path, {remote: true}) do -%>
              <p>
              <%= label_tag :email %>
              <%= text_field_tag :email %>
              <p/>
              <p>
              <%= label_tag "First Name" %>
              <%= text_field_tag :first_name %>
              <p/>
              <p>
              <%= label_tag "Last Name" %>
              <%= text_field_tag :last_name %>
              <p/>
              <%= hidden_field_tag 'event_id', @event.id %>
              <p class="submit_register">
              <%= submit_tag "Register for this event" %>
                  <span class="help-block">Enter your name and email above and the link will be magically revealed</span>
              <p/>
            <%- end -%>
          </div>
        <%- end -%>

......用这个coffeescript:

events.js.coffee

jQuery ->
    $(".location").hide()
    $(".submit_register").click ->
        $(".location").show()
        $(".registration_form").hide()

我在coffeescript中遇到的$(".location").hide()问题已应用于我的所有活动,但我只希望将其应用于@event.requires_registration?true的活动。

1 个答案:

答案 0 :(得分:1)

感谢https://stackoverflow.com/users/350087/apneadiving带领我朝着正确的方向前进。这对我有用......

jQuery ->
    if $('div').hasClass 'form-group registration_form'
        $(".location").hide()
        $(".submit_register").click ->
            $(".location").show()
            $(".registration_form").hide()