In the example below, what is the dash doing between the class
attribute and array:

(field_helpers -
[:label, :check_box, :radio_button, :fields_for, :hidden_field, :file_field]).each
do |selector|

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Jordon Bedwell at Sep 8, 2012 at 6:49 pm
    In ruby a minus on an array removes elements. So its removing elements
    from the array.
    On Sep 8, 2012 1:42 PM, "John Merlino" wrote:

    In the example below, what is the dash doing between the class
    attribute and array:

    (field_helpers -
    [:label, :check_box, :radio_button, :fields_for, :hidden_field,
    :file_field]).each
    do |selector|

    --
    You received this message because you are subscribed to the Google Groups
    "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to
    rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • John Merlino at Sep 8, 2012 at 7:50 pm
    Yeah so I would like to see the returned array of instance methods of
    field_helpers of FormBuilder. I try to return it in console:

    1.9.3p0 :016 > FormBuilder.field_helpers
    NoMethodError: undefined method `field_helpers' for FormBuilder:Class

    Why is it saying undefined method field_helpers when that method
    exists on the FormBuilder class:

    class_attribute :field_helpers
    On Sep 8, 2:49 pm, Jordon Bedwell wrote:
    In ruby a minus on an array removes elements.   So its removing elements
    from the array.
    On Sep 8, 2012 1:42 PM, "John Merlino" wrote:






    In the example below, what is the dash doing between the class
    attribute and array:
    (field_helpers -
    [:label, :check_box, :radio_button, :fields_for, :hidden_field,
    :file_field]).each
    do |selector|
    --
    You received this message because you are subscribed to the Google Groups
    "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to
    rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visithttps://groups.google.com/groups/opt_out.
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • John Merlino at Sep 9, 2012 at 5:33 pm
    ok this was oversight on my part. First of all, instead of using the
    helper helper in the console, you can directly access actionview just
    by specifying the constant. So
    ActionView::Helpers::FormBuilder.instance_methods would work. But what
    was oversight is that I was wondering that FormBuilder's field_helpers
    class method which returns an array of methods for the object was
    actually removing all the methods it defines. But if you look at its
    assignment, it is grabbing the methods of FormHelper, not FormBuilder.
    It does "FormHelper.instance_methods" and FormHelper is what defines
    the key methods that we often invoke on the form builder that have
    generic output:

    ActionView::Helpers::FormHelper.instance_methods
    =>
    [:convert_to_model, :form_for, :fields_for, :label, :text_field, :password_field, :hidden_field, :file_field, :text_area, :check_box, :radio_button, :search_field, :telephone_field, :phone_field, :url_field, :email_field, :number_field, :range_field]

    The reason why we
    exclude :label, :check_box, :radio_button, :fields_for, :hidden_field, :file_field
    is because they have their own unqiue definition which is done in the
    form builder itself.

    So whene we cal text_field, for example, that method was dybamically
    built using class_eval. and what it does is just call the method from
    selector.inspect on tempalte, and of course the tempalte is
    ActionView::Helpers::FormHelper, since that is also where form_for
    itself is defined. and in our view we invoke form_for, where self is
    ActionView with tha tmodule included.
    On Sep 8, 3:51 pm, John Merlino wrote:
    Yeah so I would like to see the returned array of instance methods of
    field_helpers of FormBuilder. I try to return it in console:

    1.9.3p0 :016 > FormBuilder.field_helpers
    NoMethodError: undefined method `field_helpers' for FormBuilder:Class

    Why is it saying undefined method field_helpers when that method
    exists on the FormBuilder class:

    class_attribute :field_helpers

    On Sep 8, 2:49 pm, Jordon Bedwell wrote:






    In ruby a minus on an array removes elements.   So its removing elements
    from the array.
    On Sep 8, 2012 1:42 PM, "John Merlino" wrote:

    In the example below, what is the dash doing between the class
    attribute and array:
    (field_helpers -
    [:label, :check_box, :radio_button, :fields_for, :hidden_field,
    :file_field]).each
    do |selector|
    --
    You received this message because you are subscribed to the Google Groups
    "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to
    rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visithttps://groups.google.com/groups/opt_out.
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Иван Бишевац at Sep 8, 2012 at 7:17 pm
    2012/9/8 John Merlino <stoicism1@aol.com>
    In the example below, what is the dash doing between the class
    attribute and array:

    (field_helpers -
    [:label, :check_box, :radio_button, :fields_for, :hidden_field,
    :file_field]).each
    do |selector|
    Look at http://www.ruby-doc.org/core-1.9.3/Array.html#method-i-2D

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedSep 8, '12 at 6:42p
activeSep 9, '12 at 5:33p
posts5
users3
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2022 Grokbase