class Test < ActiveRecord::Base attr_accessible :time_limit # declared to be :integer in migration # omitted end
When I generate a simple_form for an instance of Test, <%= f.input :time_limit %>
renders the text-field with counter control (small-up/down arrows to increment/decrement integer value) as it gives that field a class: integer and numeric. This is expected.
However, when I have an instance of this model Test inside another model say Exam and I use simple_fields_for like: <%= simple_form_for @exam do |f| %> .... <%= f.simple_fields_for :test do |test_form| %> <%= test_form.input :time_limit %> <% end %> <%end %>
I find that the same field is now rendered with string class losing the counter control! Even if I use :input_html => "numeric integer", since in the rendered HTML (:class = "string numeric integer"), "string" prevails, the counter control is lost.
Do you have "accept_nested_attributes_for" configured for test in the Exam model? It seems the "fields_for :test" is not being binded to an object, which means it cannot verify the column type to render the proper field, defaulting to string.
On Fri, Jan 20, 2012 at 12:57 PM, kedar mhaswade <kedar.mhasw...@gmail.com>wrote:
> I have a model with an integer field, time_limit:
> class Test < ActiveRecord::Base > attr_accessible :time_limit # declared to be :integer in migration > # omitted > end
> When I generate a simple_form for an instance of Test, > <%= f.input :time_limit %>
> renders the text-field with counter control (small-up/down arrows to > increment/decrement integer value) as it gives that field a class: integer > and numeric. > This is expected.
> However, when I have an instance of this model Test inside another model > say Exam and I use simple_fields_for > like: > <%= simple_form_for @exam do |f| %> > .... > <%= f.simple_fields_for :test do |test_form| %> > <%= test_form.input :time_limit %> > <% end %> > <%end %>
> I find that the same field is now rendered with string class losing the > counter control! Even if I use :input_html => "numeric integer", since in > the rendered HTML (:class = "string numeric integer"), "string" prevails, > the counter control is lost.
Thanks Carlos, I will try out accept_nested_attributes_for. I somehow think that there's something weird going on. Let me investigate. I worked around the problem by using :as => :integer.
On Fri, Jan 20, 2012 at 7:43 AM, Carlos Antonio da Silva <
carlosantoniodasi...@gmail.com> wrote: > Do you have "accept_nested_attributes_for" configured for test in the Exam > model? It seems the "fields_for :test" is not being binded to an object, > which means it cannot verify the column type to render the proper field, > defaulting to string.
> On Fri, Jan 20, 2012 at 12:57 PM, kedar mhaswade <kedar.mhasw...@gmail.com > > wrote:
>> I have a model with an integer field, time_limit:
>> class Test < ActiveRecord::Base >> attr_accessible :time_limit # declared to be :integer in migration >> # omitted >> end
>> When I generate a simple_form for an instance of Test, >> <%= f.input :time_limit %>
>> renders the text-field with counter control (small-up/down arrows to >> increment/decrement integer value) as it gives that field a class: integer >> and numeric. >> This is expected.
>> However, when I have an instance of this model Test inside another model >> say Exam and I use simple_fields_for >> like: >> <%= simple_form_for @exam do |f| %> >> .... >> <%= f.simple_fields_for :test do |test_form| %> >> <%= test_form.input :time_limit %> >> <% end %> >> <%end %>
>> I find that the same field is now rendered with string class losing the >> counter control! Even if I use :input_html => "numeric integer", since in >> the rendered HTML (:class = "string numeric integer"), "string" prevails, >> the counter control is lost.
fields_for can receive an object to work with - basically the same way as form_for does, and SimpleForm uses the object to reflect column information. Without object, no column information, thus all fields will be considered string.
You can always give an extra argument to fields_for with an object if you want, for instance:
f.fields_for :test, Test.new
And of course, force the field type using the :as, just like you did :)
On Sat, Jan 21, 2012 at 11:42 AM, kedar mhaswade <kedar.mhasw...@gmail.com>wrote:
> Thanks Carlos, I will try out accept_nested_attributes_for. I somehow > think that there's something weird going on. Let me investigate. > I worked around the problem by using :as => :integer.
> On Fri, Jan 20, 2012 at 7:43 AM, Carlos Antonio da Silva < > carlosantoniodasi...@gmail.com> wrote:
>> Do you have "accept_nested_attributes_for" configured for test in the >> Exam model? It seems the "fields_for :test" is not being binded to an >> object, which means it cannot verify the column type to render the proper >> field, defaulting to string.
>> On Fri, Jan 20, 2012 at 12:57 PM, kedar mhaswade < >> kedar.mhasw...@gmail.com> wrote:
>>> I have a model with an integer field, time_limit:
>>> class Test < ActiveRecord::Base >>> attr_accessible :time_limit # declared to be :integer in migration >>> # omitted >>> end
>>> When I generate a simple_form for an instance of Test, >>> <%= f.input :time_limit %>
>>> renders the text-field with counter control (small-up/down arrows to >>> increment/decrement integer value) as it gives that field a class: integer >>> and numeric. >>> This is expected.
>>> However, when I have an instance of this model Test inside another model >>> say Exam and I use simple_fields_for >>> like: >>> <%= simple_form_for @exam do |f| %> >>> .... >>> <%= f.simple_fields_for :test do |test_form| %> >>> <%= test_form.input :time_limit %> >>> <% end %> >>> <%end %>
>>> I find that the same field is now rendered with string class losing the >>> counter control! Even if I use :input_html => "numeric integer", since in >>> the rendered HTML (:class = "string numeric integer"), "string" prevails, >>> the counter control is lost.