Search code examples
javascriptruby-on-rails-3.1controller

Ruby on Rails: Calling controller method from javascript


Is it possible to call controller method from a javascript? I mean it's not from view(html.erb) also not from js.erb. I want to call method from .js file, which in public folder. Thank you


Solution

  • Yes, you want to do AJAX calls. You probably want to use jquery which would be simpler than straight javascript. Here is a link to a w3schools tutorial on jquery AJAX calls. Here is another SO post with a link to a gist with some example code or you may want to Google jQuery, AJAX and Rails 3.