Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Direct Jquery Remoting
Ruby
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
app/controllers
config
doc
lib
log
public
script
spec
vendor/assets/javascripts
.document
.gitignore
.rspec
Gemfile
MIT-LICENSE.txt
README.md
Rakefile
config.ru
djr.gemspec

README.md

Build

Build Status

DJR

DJR (Direct jQuery Remoting) will generate the JavaScript code from Rails Controllers to allow browsers to securely call into Ruby code almost as if it was running locally

Getting started

Add it to your Gemfile with:

gem 'djr'

Run the bundle command to install it.

Configure assets in app/assets/application.js file:

//= require jquery
//= require djr
//= require_tree .

Import script in your pages:

<script type="text/javascript" charset="utf-8" src="/djr"></script>

In javascript, call your Controller like:

productsController = new ProductsController

productsController.save({
    name: "IPhone 4s",
    value: "500.00"
}, callbackFunction);

//or more complete

productsController.index({
    query: "IPhone"
}, function(productsListAsJson){
    showProductsFunction(productsListAsJson);
}, function(error) {
    errorHandler(error);
});

Your controller should be something like that:

class ProductsController < ApplicationController

    respond_to :html, :json

    def index
        @query = params[:query]
        @products = Product.search do
            fulltext @query
        end
        respond_with @products
    end

end

Conventions

controller.action( dataAsJson, callbackFunction, errorHandler );

License

MIT License. Copyright (c) 2012 Milfont Consulting. http://milfont.org

Something went wrong with that request. Please try again.