Automatic parameter bindings in controllers by argument names (like in Merb)

Is there any reason why Rails decided not to support argument binding in controller actions like Merb?

https://github.com/wycats/merb/tree/master/merb-action-args

The idea is to be able to do stuff like this:

class MyController < ApplicationController
     def find(term, limit=10, offset=0)
         # if params[:limit] exists, it would be passed as the limit argument when the method is called by ActionDispatcher. Otherwise, 10 would be assumed
         # raise BindingNotPresent unless params[:term].present?
     end
end

Grails 2 will also bring such kind of feature and, as types can be optionally declared in Groovy, it is able to automatically type cast params too.

As a curious note, Perl 6 has a great feature (among several others) that will enable you to write a main function that will bind arguments from the command line to the function params names too:

http://perlgeek.de/en/article/5-to-6#post_14

I don’t know if this was discussed already, but it’s definitely a great idea!

Great idea, +1.

If you're already on Ruby 1.9, you can try this gem.
https://github.com/asakusarb/action_args

I know the same thing could be done on Ruby 1.8 in merb_action_args way,
but the hack is too dirty and horrible.

So, if you're still on Ruby 1.8 but want this feature on your Rails app,
moving to Ruby 1.9 and bundling this gem is probably the easiest way.

Thanks for pointing out this gem.

I don't use Ruby 1.8 for a long time (except in applications such as Gitorious that still use old Rails that didn't supported 1.9 very well with regards to unicode).

But since I'm suggesting this to be included directly in Rails, I think it should support Ruby 1.8 too until Rails drops support for 1.8.

Maybe Rails 3.2 will drop 1.8 support and this could be included in next major Rails version...

Cheers,

Rodrigo.

That's the plan for Rails 4.

+1