views:

47

answers:

2

I'm incredibly new to Rails and programming in general. Built my first, fairly static, Rails app. I have 100's of products (specifically t-shirts) that all have associated colors (RGB values) and sizes that I need to display on several product pages.

Rather than hand-coding this information, I assume I need to build a database for it. If I create a Product model and products controller with the correct table headers, how do I get the data into the table?

Most of the documentation that I've been reading has to do with building tables that hold user-generated dynamic content, not large lists like the one I'm trying to create.

Thanks!

+3  A: 

You probably need to seed your data in: http://www.agileweboperations.com/seed-data-in-ruby-on-rails/

Yannis
+1 for teaching me something new.
Trip
A: 

Hey Teecraft, welcome to RoR.

Well you count as User-Generated Content as well. If you have a pre-existing database that you just need to migrate over, that's a different story. But it sounds like you're starting from scratch. Excuse me if I'm wrong.

To start from scratch, you should follow the tutorials.

Create your scaffold ( scaffolds are great for beginners ).

rails g scaffold Product productType:string color:int size:string
rake db:migrate

Then start trucking away at all that info. If you ever want to migrate to a new application, then you can easily mysqldump your db to a new app.

Trip
Thanks Trip. Two follow up questions. 1) How do I enter the data... via the command line? 2) Do you have a recommendation for how I could structure the table if every productType could have anywhere from 5 to 40 RGB color values each?
teecraft
1. Yikes, command line sounds crazy. I'd recommend taking advantage of the graphic user interface of a website to do that. I've built website before just to manually add data to a database before. No sweat. Command line is this `a = Object.new(:attribute => "foobar") /next line/ a.save` . 2. For Colors, notice how I put that as an Integer above. I did that because a hex is a six digit number. Stay with that convention and it will open up many avenues to you programmatically and with flexibility later on. Let me know if that helps you. Good luck.
Trip
Thanks again. Now I'm in the throes of figuring out how to upload images using Paperclip... ugh...
teecraft
@teecraft, watch this tutorial http://railscasts.com/episodes/134-paperclip . :)
Trip