Only Bolivian Here
Only Bolivian Here

Reputation: 36733

Is this "the ruby way" of creating a database driven website, models first?

I wrote down on a simple text file the script I have to run to generate my models for my Rails 3.2.1 app:

rails generate model Champion name:string title:string story:string smallpicture:string largepicture:string spotlight:string

rails generate model Item code:int name:string description:string cost:string

rails generate model RecommendedItems mapname:string item1:int item2:int item3:int item4:int item5:int item6:int champion:references

rails generate model GoodAgainst reason:string champion:references

rails generate model BadAgainst reason:string champion:references

rails generate model Spell name:string description:string effect:string cost:string range:string champion:references

rails generate model Tip tiptext:string champion:references

rails generate model ChampionStat name:string value:string modifier:string champion:references

rails generate model User summonername:string email:string password:string confirmpassword:string location:string canvoteonfavoritechampion:boolean

rails generate model FavoriteStream url:string user:references

rails generate model ChampionRanking startweek:datetime endofweek:datetime champion:references

rails generate model CustomBuilds item1:int item2:int item3:int item4:int item5:int item6:int champion:references

Now, I realize that I can run generate scaffold, but I figured I would run model first and then add the scaffolding on a need only basis. Is this possible?

Is this the way you create a Ruby on Rails application? I drew out the database on paper and created the foreign key relationship and use the foo:references notation to note the relationships.

Is this correct?

Upvotes: 1

Views: 375

Answers (2)

Andrew Cetinic
Andrew Cetinic

Reputation: 2835

It is definitely one way to go about creating a Ruby on Rails application.

Depends on the developer, complexity of the application and how much of the design has been already completed. To get started you can load a schema directly from a existing database, and then create models for each of your relationships (my preference, as long as you know the Rails naming conventions). Relationships can get complex, so generating models is not always the most ideal option.

FYI: Ryan has a handy gem to generate scaffolding, layout files, authentication, and more. https://github.com/ryanb/nifty-generators

Upvotes: 0

David Grayson
David Grayson

Reputation: 87386

Assuming that the syntax of your commands is correct, there's nothing objectively wrong with what you are doing, but I don't think it's the way Rails was meant to be used.

What your doing is very not agile. In agile programming, you focus on delivering working software early and often. So you would just make the minimal number of tables and columns to get the first few features working. Then once you have done that and shown it to your customers/users, you would decide what feature to add next and add the tables and columns you need for that. Eventually you would have a complete app.

I think this approach has some benefits because you might learn some things about database design during the early phases of the project that help improve your decisions in the later part of the project.

I recommend reading Agile Web Development with Rails if you want to see an example of how an app would be developed this way.

Another good practice is test-driven development. The idea is you should only write code to fix broken tests. It looks like you aren't doing that.

Upvotes: 2

Related Questions