collin / rails-action-args

Porting this. Must have it. <3 Action Args. Running against http://github.com/rails/rails master branch. Right now the tests assume this is sitting at the root of the rails repo. Will find a batter place for it once all the tests pass.

This URL has Read+Write access

name age message
file .gitignore Loading commit data...
file LICENSE
file README
file Rakefile
file TODO
file ThankYou
file init.rb
directory lib/
directory test/
README
Not working yet, but close :) Four failing tests.

Tests currently assume this directory is living inside the core rails repo
along side actionpack/ activerecord/ etc.

Going to figure out a better place to put it once I get the tests passing.

rails-action-args
================

A plugin for the Rails framework that provides support for arguments to actions that 
come in from the query.

==== Basics

{{[
class Foo < ApplicationController::Base
  def bar(baz)
    bar
  end
end
]}}

Hitting "/foo/bar?baz=bat" will call foo("bat").

Hitting "/foo/bar" will raise a BadRequest (Status 400) error.

==== Defaults

{{[
class Foo < ApplicationController::Base
  include AbstractController::ActionArgs
  def bar(baz, bat = "hola")
    "#{baz} #{bat}"
  end
end
]}}

Hitting "/foo/bar?baz=bat" will call foo("bat", "hola")

Hitting "/foo/bar?baz=bat&bat=whaa" will call foo("bat", "whaa")

Hitting "/foo/bar" will still raise a BadRequest.

==== Out of order defaults

{{[
class Foo < ApplicationController::Base
  include AbstractController::ActionArgs
  def bar(one, two = "dos", three = "tres")
    "#{one} #{two} #{three}"
  end
end
]}}

The interesting thing here is that hitting "/foo/bar?one=uno&three=three" will call
foo("uno", "dos", "three"). In other words, the defaults can be in any order, and 
rails-action-args will figure out where to fill in the holes.