collin / rails-action-args
- Source
- Commits
- Network (1)
- Issues (0)
- Downloads (0)
- Wiki (1)
- Graphs
-
Branch:
master
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.

