RubyFlow The Ruby and Rails community linklog

Find your happy_place with javascript and Rails

happy_place allows you to call js functions and pass in variables and partials. It has a simple interface which allows you to write object oriented javascript and use these objects in your controllers.

Here is an example posts controller setup that will respond to html and js. When format is js it will call the coffee script class with the index function passing in a partial with the html that you want to replace. class PostsController  def index   @posts = Posts.all

  respond_to do |format|
      format.js { js partials: {posts: "posts"} }
      format.html
&nbsp;&nbsp;&nbsp;end   &nbsp;&nbsp;end end </code> You can put the following code anywhere but this is where I would put it <code> # app/assets/controllers/posts_controllers.coffee class this.PostsController   &nbsp;&nbsp;constructor: ->

  @index: (args) ->    $(“.posts_table”).html(args.posts); </code>

No need for a js view!

Post a comment

You can use basic HTML markup (e.g. <a>) or Markdown.

As you are not logged in, you will be
directed via GitHub to signup or sign in