Mix ruby code with js.coffee script
ajax, coffeescript, javascript, jquery, ruby-on-rails
Solution
If it's a code for you static asset then it's obvious you won't be able to put some server-side dynamics into it. It'll be converted into a plain JavaScript-snippet and placed into your app's `public` folder.
If you have your view called *.coffee then you already have done all the preparations. The views named this way will be automatically pre-processed with the ERb engine (via `<%= ... %>`):
in views/some/thing.coffee:
alert "Server's time is <%= Time.now %>"
Problem
I have ajax links on my view, on which I want to check password before they're sent to the actual action, as I am using devise controller, i am restricted to the use of specific password check. Following is the coffee script I wish to use for the validation. .<%= link_to "CANCEL PAYMENT", { :action => "some_action", :info => n.id },class: "css_class",:remote => true %> I am using the above link I am looking for a following kind of code. ``` $("a.css_class").live "click", -> password_variable = prompt("Enter password", "password") if |ruby-code|current_user.valid_password?(password_variable)|ruby-code| true else alert "You entered wrong password" false ``` How'll the ruby code work with coffee script mix.