Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A port of merb-action-args to Rails 3

tree: cc4770d83f

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 .document
Octocat-spinner-32 .gitignore
Octocat-spinner-32 Gemfile
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.markdown
Octocat-spinner-32 Rakefile
Octocat-spinner-32 VERSION.yml
Octocat-spinner-32 rails-action-args.gemspec
README.markdown

rails-action-args

Rails Action Args allows you to accept the parameters to you action as arguments to the action method.

The best way to demonstrate this is with a quick example.

First you need to include ActionArgs in your ApplicationController

class ApplicationController < ActionController::Base
  include ActionArgs
end

Then you simply accept arguments to your methods.

class PostsController < ApplicationController
  respond_to :json

  def show(id)
    @post = Post.find(id)
    respond_with @post
  end
end

class MyApp < Rails::Application
  root :to => "posts#show"
end

Now if this is called with {:id => 1} in the params, the id will be set to 1.

> curl http://localhost:3000?id=1
{"id": 1, "title":"Lorem ipsum dolor"}

If you call the action without the correct parameter, you get a 400 Bad Request

> curl http://localhost:3000
HTTP/1.1 400 Bad Request

You can also supply default arguments as normal.

class PostsController < ApplicationController
  respond_to :json

  def show(id=4)
    @post = Post.find(id)
    respond_with @post
  end
end

> curl http://localhost:3000?id=1
{"id": 4, "title":"Consectur sit amet"}

Authors

This plugin is very heavily influenced by the merb-action-args plugin. All authors of that plugin helped make this one happen.

Special thanks to Yehuda Katz for writing much of the original merb plugin and helping convert this to Rails 3.

Copyright

Copyright (c) 2010 Andy Delcambre. See LICENSE for details.

Something went wrong with that request. Please try again.