A port of merb-action-args to Rails 3
Ruby
Latest commit c4c0af1 Apr 25, 2011 Andy Delcambre Merged pull request #1 from AF83/master.
Methopara is not needed for Ruby 1.9.2 and up
Permalink
Failed to load latest commit information.
lib Make vm_args ruby 1.9.2 friendly Jan 11, 2011
spec
.document
.gitignore
Gemfile
LICENSE
README.markdown
Rakefile Use active_support/concern for module inclusion helpers Apr 3, 2010
VERSION.yml
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.