Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Elegant responder for ajax requests
Ruby
tree: 5adf922877

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
gemfiles
lib
spec
.gitignore
.travis.yml
Gemfile
LICENSE.txt
README.rdoc
Rakefile
rjax.gemspec

README.rdoc

Rjax

Solve template dispatch on ajax request

Build
Status Gem Version

Installation

Add this line to your application's Gemfile:

gem 'rjax'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rjax

Usage

Rjax will be useful if you have a lot action which serve http and ajax request. It might looks like:

def index
  @users = User.all
  render :partials => 'users', :locals => { :users => @users }  if request.xhr?
  # or
  render :index_ajax if request.xhr?
end

Rjax replace it with single method call

def index
  @users = User.all
  rjax
end
# render index_rjax template

def index
  @users = User.all
  rjax @users
end
# render _user_rjax or _user partial with variable `user`

def index
  @users = User.all
  rjax :users => @users, :other => :variable
end
# render _users_rjax or _users partial with variables users & other

def show
  @user = User.find(params[:id])
  rjax @user
end
# render _user_rjax or _user partial with `user` variable

The name of partial is based on controller name. If you don't like rjax suffix or it's out your team's convention feel free to configure wrapper:

# config/initializers/rjax.rb
Rjax.config do |config|
  config.suffix = "suffix"
  config.prefix = "prefix"
end

prefix_%action_name%_suffix

_prefix_%partial_name%_suffix

Contributing

  1. Fork it

  2. Create your feature branch (`git checkout -b my-new-feature`)

  3. Commit your changes (`git commit -am 'Add some feature'`)

  4. Push to the branch (`git push origin my-new-feature`)

  5. Create new Pull Request

Something went wrong with that request. Please try again.