Rails syntax in application.js

Is it possible to use the rails syntax inside of application.js file.
Basically, I want to use remote_function call inside of a javascript
function.
I know I could use the Ajax.Request but then I have a problem with an
authenticity token.

I’ve tried this:
function callRemote(){
<%= remote_function(:url => {:action => :my_function}) %>
}
And this syntax does not fly in the application.js.
So is it possible to use the rails syntax in some way in application.js
file?

No. This is just a javascript file, you cannot use Rails syntax in it.

Greg L. wrote:

Is it possible to use the rails syntax inside of application.js file.
Basically, I want to use remote_function call inside of a javascript
function.
I know I could use the Ajax.Request but then I have a problem with an
authenticity token.

I’ve tried this:
function callRemote(){
<%= remote_function(:url => {:action => :my_function}) %>
}
And this syntax does not fly in the application.js.
So is it possible to use the rails syntax in some way in application.js
file?

ruby script/generate controller Javascripts

add “map.connect ‘javascripts/:action.js’” to config/routes.rb

create app/views/javascripts/app.erb

add the line “caches_page :app” to
app/controllers/javascripts_controller.rb

in your template add “javascript_include_tag(:app)”


now you have app.js
dynamically generated from erb
and cached.