Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
type information is lost in simple_fields_for?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
kedar mhaswade  
View profile  
 More options Jan 20 2012, 9:57 am
From: kedar mhaswade <kedar.mhasw...@gmail.com>
Date: Fri, 20 Jan 2012 06:57:55 -0800
Local: Fri, Jan 20 2012 9:57 am
Subject: type information is lost in simple_fields_for?

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.

What am I doing wrong?

Regards,
Kedar


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Carlos Antonio da Silva  
View profile  
 More options Jan 20 2012, 10:43 am
From: Carlos Antonio da Silva <carlosantoniodasi...@gmail.com>
Date: Fri, 20 Jan 2012 13:43:38 -0200
Local: Fri, Jan 20 2012 10:43 am
Subject: Re: type information is lost in simple_fields_for?

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:

--
At.
Carlos Antonio

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
kedar mhaswade  
View profile  
 More options Jan 21 2012, 8:42 am
From: kedar mhaswade <kedar.mhasw...@gmail.com>
Date: Sat, 21 Jan 2012 05:42:27 -0800
Local: Sat, Jan 21 2012 8:42 am
Subject: Re: type information is lost in simple_fields_for?

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 <


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Carlos Antonio da Silva  
View profile  
 More options Jan 21 2012, 9:12 am
From: Carlos Antonio da Silva <carlosantoniodasi...@gmail.com>
Date: Sat, 21 Jan 2012 12:12:35 -0200
Local: Sat, Jan 21 2012 9:12 am
Subject: Re: type information is lost in simple_fields_for?

Ok, please let us know if you find anything.

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:

--
At.
Carlos Antonio

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »