Question

I'm trying to setup alertify in my rails project without using any gems and I'm not able to get a hello world implementation working. I've spent over half a day on this and not sure why.

In application.js

//= require alertify

In vendor/assets/javascripts

alertify.js

In front.js.coffee

alertify.alert "I'm an alertify alert"

In vendor/assets/stylesheets

alertify.default.css

Nothing from the console. I'm stuck, what am I missing? Having a similar problem with another plugin and I've tried calling is form the view using script tags and I get a Uncaught ReferenceError: alertify is not defined error.

Was it helpful?

Solution

I tried to reproduce your problem through building a simple test app - I've put my test rails app on github, for comparison.

My best guess is that the javascript in your front.js.coffee is executed before alertify (and the DOM) is loaded. In my case, the following worked just fine:

$ ->
  alertify.alert "I'm an alertify alert"

This compiles to $(function(){alertify.alert("I'm an alertify alert");});. See the jQuery documentation for details on the $ function.

By the way, you should also place alertify.core.css in vendor/assets/stylesheets and require it in application.css:

*= require alertify.core
*= require alertify.default

The later does not solve the problem you mentioned, but let's alertify look good ;)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top