Zack Shapiro
Zack Shapiro

Reputation: 6998

What's the proper way to set up date fields for a database?

So I have 3 fields in my HTML, lunchMonth, lunchDay and lunchYear

lunchMonth and lunchDay are Select tags with option tags for months and days remaining in the year. lunchYear is set to 2011.

I've set up a form but I need to generate a scaffold to take these 3 values.

What's the proper way to do this?

Rails generate scaffold Date month:string date:integer year:integer

Is that right?

Upvotes: 0

Views: 137

Answers (1)

user266647
user266647

Reputation:

You don't need to use select tags or write out your HTML with scaffold rails will do that for you. do rails generate scaffold LunchTimes lunch_on:date (NOTE: rails has a date data type.)

and rails will generate views in app/views/lunch_times/* that use the select_date helper to generate the needed HTML.

it will also generate a model in app/models/lunch_time.rb and a controller: app/controllers/lunch_times_constrollers.rb

EDIT:

I'd encourage you to checkout the Rails Guides here: http://guides.rubyonrails.org/index.html

http://api.rubyonrails.org is also a good reference.

I've found them very helpful.

Upvotes: 2

Related Questions