Forum: Ruby on Rails Rails 1.2 Bug (?): to_text_area_tag

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Brendon Davidson (Guest)
on 2007-02-28 05:51
Hi all,

I'm fairly new to rails and thus might be missing something here, but I
think I have found a but in ActionPack.  If this is not the right place
to post this, please let me know where.  I discovered this issue while
attempting to use the lastest edge version of ajax_scaffold (mooey, MUI,
whatever it's going to be called).  I kept getting the error:

private method `split' called for 20:Fixnum

Curious as to what was going on, I decided to delve into the code a bit.
I found that mooey was calling the input(...) form helper to generate
the input fields for models and sends in the option :size => 20.  input
then calls to_text_area_tag.  Well, since :size is a Fixnum and
to_text_area_tag expects it to be a string, we get the above noted
error.

This does not appear to be an error with the mooey code, however, since
input(...) seems to be intended to dynamically create the correct tag
depending on the "method" type.  Therefore, if the method being used
with input(...) was a string, it would call to_text_input_tag which
assumes that :size is a Fixnum and everything would be alright.

What I did next was to change to_text_area_tag to recognize detect if
:size was a Fixnum.  If it is, simply set both :options["rows"] and
:options["cols"] to the value of :size.  Otherwise, use the original
logic to split the string and determine the cols/rows.

I hope this is clear and helps somewhat.  I'm not sure that this is the
proper solution, but it does seem to be a legitimate issue.  Below is
the code for my new to_text_area_tag:

      def to_text_area_tag(options = {})
        options =
DEFAULT_TEXT_AREA_OPTIONS.merge(options.stringify_keys)
        add_default_name_and_id(options)

        if size = options.delete("size")
          if size.kind_of? Fixnum
            options["cols"] = size
            options["rows"] = size
          else
            options["cols"], options["rows"] = size.split("x")
          end
        end

        content_tag("textarea", html_escape(options.delete('value') ||
value_before_type_cast(object)), options)
      end

Now that I've gotten that out of the way, I must say that rails is
AWESOME!!  I'm able to develop real working apps so much quicker than
I've ever done in php or java.  Great stuff!  Keep up the good work.

Brendon Davidson
Brendon Davidson (Guest)
on 2007-02-28 05:54
> This does not appear to be an error with the mooey code, however, since
> input(...) seems to be intended to dynamically create the correct tag
> depending on the "method" type.  Therefore, if the method being used
> with input(...) was a string, it would call to_text_input_tag which
> assumes that :size is a Fixnum and everything would be alright.


I actually meant to_input_field_tag.  to_text_input_tag does not exist.


Brendon Davidson
This topic is locked and can not be replied to.