Rodrigo Rosenfeld Rosas
2011-Sep-08 01:54 UTC
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
---
# 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 rubyonrails-core@googlegroups.com.
To unsubscribe from this group, send email to
rubyonrails-core+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en.
Andrés Mejía
2011-Sep-08 02:25 UTC
Re: Automatic parameter bindings in controllers by argument names (like in Merb)
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 <rr.rosas@gmail.com>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<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<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 rubyonrails-core@googlegroups.**com<rubyonrails-core@googlegroups.com> > . > To unsubscribe from this group, send email to > rubyonrails-core+unsubscribe@**googlegroups.com<rubyonrails-core%2Bunsubscribe@googlegroups.com> > . > For more options, visit this group at http://groups.google.com/** > group/rubyonrails-core?hl=en<http://groups.google.com/group/rubyonrails-core?hl=en> > . > >-- 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 rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Bruno Ferreira Pinto
2011-Sep-08 04:15 UTC
Re: Automatic parameter bindings in controllers by argument names (like in Merb)
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 <rr.rosas@gmail.com (mailto:rr.rosas@gmail.com)> 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 (http://doit.pl) > > > > #!/usr/bin/perl6 > > sub MAIN($path, :$force, :$recursive, :$home = ''~/'') { > > # do stuff here > > } > > > > # command line > > $ ./doit.pl (http://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 rubyonrails-core@googlegroups.com (mailto:rubyonrails-core@googlegroups.com). > > To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com (mailto:rubyonrails-core%2Bunsubscribe@googlegroups.com). > > For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en. > > > > -- > 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 rubyonrails-core@googlegroups.com (mailto:rubyonrails-core@googlegroups.com). > To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com (mailto:rubyonrails-core+unsubscribe@googlegroups.com). > For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.-- 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 rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Akira Matsuda
2011-Sep-08 05:39 UTC
Re: Automatic parameter bindings in controllers by argument names (like in Merb)
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<ronnie@dio.jp> On Thu, Sep 8, 2011 at 1:15 PM, Bruno Ferreira Pinto <brunoferreirapinto@gmail.com> 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 <rr.rosas@gmail.com> > 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 rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Rodrigo Rosenfeld Rosas
2011-Sep-08 12:31 UTC
Re: Automatic parameter bindings in controllers by argument names (like in Merb)
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. Em 08-09-2011 02:39, Akira Matsuda escreveu:> 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. >-- 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 rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Xavier Noria
2011-Sep-08 13:39 UTC
Re: Automatic parameter bindings in controllers by argument names (like in Merb)
On Thu, Sep 8, 2011 at 2:31 PM, Rodrigo Rosenfeld Rosas <rr.rosas@gmail.com> wrote:> Maybe Rails 3.2 will drop 1.8 support and this could be included in next > major Rails version...That''s the plan for Rails 4. -- 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 rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Everton Moreth
2011-Sep-08 14:40 UTC
Re: Automatic parameter bindings in controllers by argument names (like in Merb)
+1 On Thu, Sep 8, 2011 at 10:39 AM, Xavier Noria <fxn@hashref.com> wrote:> On Thu, Sep 8, 2011 at 2:31 PM, Rodrigo Rosenfeld Rosas > <rr.rosas@gmail.com> wrote: > > > Maybe Rails 3.2 will drop 1.8 support and this could be included in next > > major Rails version... > > That''s the plan for Rails 4. > > -- > 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 rubyonrails-core@googlegroups.com. > To unsubscribe from this group, send email to > rubyonrails-core+unsubscribe@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-core?hl=en. > >-- 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 rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.