0

I'm developing a rails application for school and I can't figure out why these events never get triggered. This is only my second time using coffeescript. The first time was on this same app and it works great. I've searched around on stackoverflow and looked at the jquery API but I can't figure out where I'm going wrong? I even tried changing the <input> tag in question to a <span> and the event to "click". That is the exact setup I have for my other piece of coffeescript(which works)... But here it doesn't work. I haven't even started the functionality I'm aiming for. This is just a sanity check that isn't going so well.

[assets/javascripts/calculator.coffee]

$ ->
  $("#foot_count").on("keyup change paste", update)

update = ->
  console.log("askhdkajshk")

[views/site/calculator.html.erb]

<div id="main">
  <div class="large_main_container">
    <h1>Fill out this form to get a rough estimate.</h1>
    <form>
        <table>
          <tr>
            <td class="form_label">Number of Feet</td>
            <td><input class="input_field" id="foot_count" type="text"></td>
          </tr>
          <tr>
            <td class="form_label">Number of Gates</td>
            <td><input class="input_field" id="gate_count" type="text"></td>
          </tr>
          <tr>
            <td class="form_label">Estimated Price</td>
            <td id="calculated_value">Some Value</td>
          </tr>
        </table>
    </form>
  </div>
</div>

Update My problem was rendering the page with :layout => false. I'm not really sure where in assets to put this coffeescript. Time to start reading. If anyone has advice, thanks!

Update Addding <%= javascript_include_tag "application" %> to my view solved the problem.

rocktheartsm4l
  • 1,999
  • 17
  • 35
  • 1
    What says your firebug console? – BvuRVKyUVlViVIc7 Dec 04 '13 at 00:29
  • @muistooshort tried disabling turbolinks but nothing changed. http://blog.flightswithfriends.com/post/53943440505/how-to-disable-turbolinks-in-rails-4 – rocktheartsm4l Dec 04 '13 at 00:59
  • @Lichtamberg I'm using chrome's console but it doesn't print anything. – rocktheartsm4l Dec 04 '13 at 01:04
  • I don't know if this helps at all but when I use a `text_field_tag "name", "value", :onkeyup => "alert('it worked')"` the event happens. I wouldn't mind doing it this way but haven't been able to figure out how to use a function from my assets for `:onkeyup => "myFuncFromAssets"` – rocktheartsm4l Dec 04 '13 at 01:09
  • I figured out why it isn't working. I'm rendering the page with :layout => false. Now I just need to figure out where to put this coffeescript so it still gets rendered. I need the coffeescript but not the html from the layout. – rocktheartsm4l Dec 04 '13 at 01:16
  • then you should take care to load the jquery files... without them, your js wont work.. – BvuRVKyUVlViVIc7 Dec 04 '13 at 01:33
  • @Lichtamberg Yep. I believe you mean what my last update says? If you want to submit that as an answer I will mark it as correct :) – rocktheartsm4l Dec 04 '13 at 02:05
  • What exactly helped you? :) – BvuRVKyUVlViVIc7 Dec 04 '13 at 11:38
  • @Lichtamberg "take care to load the jquery files." I hadn't realized that my javascript/coffeescript in app/assets/javascripts was part of my layout. So when using :layout => false I have to manually load the javascript/coffeescript on my page. – rocktheartsm4l Dec 04 '13 at 16:12
  • Oh alright ;D Added my answer, thanks – BvuRVKyUVlViVIc7 Dec 04 '13 at 19:30

1 Answers1

0

Since you told us that you are not rendering a layout:

Take care: Probably you include the jquery-files in your layout file

-> if its not rendered, there is no jquery and your javascript wont work!

BvuRVKyUVlViVIc7
  • 11,200
  • 8
  • 55
  • 105