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. -- Akira Matsuda<[email protected]> On Thu, Sep 8, 2011 at 1:15 PM, Bruno Ferreira Pinto <[email protected]> wrote: > Great idea, +1. > -- > Atenciosamente, > Bruno Ferreira Pinto > > On quarta-feira, 7 de setembro de 2011 at 23:25, Andrés Mejía wrote: > > I don't know if this was discussed already, but it's definitely a great > idea! > > On Wed, Sep 7, 2011 at 8:54 PM, Rodrigo Rosenfeld Rosas <[email protected]> > wrote: > > 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 > > --- > > # file doit.pl > > #!/usr/bin/perl6 > sub MAIN($path, :$force, :$recursive, :$home = '~/') { > # do stuff here > } > > # command line > $ ./doit.pl --force --home=/home/someoneelse file_to_process > > --- > > I like this style of automatic bindings. > > I'm not sure if one can inspect method arguments names in Ruby 1.8 though, > but I guess this is possible since it seems that Merb supported this feature > on Ruby 1.8 too... > > Was this feature already suggested on this list? If so, what was the reason > it was rejected? Performance impact, maybe? > > Thanks in advance, > > Rodrigo. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
