0

on my web app I have a day, month ,year drop down boxes. I have a temporary render in my controller to see what is being sent into the database so I know what to migrate. however the day, month, year fields are sending in the below. But Rails generate model doesn't like the brackets. How do you over come this? Any help would be very much appreciated.

"date(3i)"=>"18", "date(2i)"=>"4", "date(1i)"=>"2014"


def change
create_table :posts do |t|
  t.text :title
  t.text :requester
  t.text :requester_email
  t.text :customer
  t.text :contact
  t.text :customer_email
  t.text :customer_phone
  t.string :type_of_change
  t.string :date(3i)

  t.timestamps
user3216968
  • 85
  • 1
  • 6

1 Answers1

0

That should just be a field called date, of type date.

the (3i) business is down to rails' multiparameter assignment system. You have a single value in the model (a date) but the UI to manipulate them breaks it down into year/month/day.

Each of the year/month/day parameters pertains to the date and the suffix indicates which parameter is which. When parameters such as

"date(3i)"=>"18", "date(2i)"=>"4", "date(1i)"=>"2014"

are assigned to a date attribute, rails knows to use Date::civil to make the date. the (1i) suffix tells rails to typecast '2014' to an integer and use it as the first parameter to Date::civil and so on

Frederick Cheung
  • 83,189
  • 8
  • 152
  • 174