Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on rails development flow/order

Now that college is out for the summer and my classes have come to an end I need to be able to keep my mind sharp over the summer. I've decided to try my hand at making a nice enough ruby on rails app from start to finish.

I've tried doing this before but the problem I always run into is: "I can't really finish this until that's done but it seems like it won't work unless I finish this other thing that need the first thing to work."

Basically my project gets out of hand really fast because I have no direction regarding what to work on and when.

My question to you, oh great and wise community of SO, is what is the most accepted way to go about developing a rails app.

Do I start with models, views, or controllers? Is it better to make the HTML first or the server code? What is the best way to get things done?

Thanks in advance!

like image 204
benbot Avatar asked Sep 20 '26 16:09

benbot


1 Answers

The Rails community strongly promotes some form of test driven development. When you're just getting started, it probably doesn't make sense to start out writing tests, but you can still keep the same approach.

So, essentially you would just try to do what you want in the browser and write what you need as you need it to accomplish that.

So getting started, just generate a new rails app and start the server. It will give you the default Rails environment information. You don't want that to be the home page, so you go to the routes.rb file and define your root address (e.g. root 'welcome#index').

Now you reload the page you get the error "Uninitialized constant WelcomeController'. So now you need a controller. Add the controller.

Now you get an error 'The action 'index' could not be found for WelcomeController'. Define the index action on your WelcomeController.

Now you get the error 'Missing template welcome/index'. Add your views/welcome/index.html.erb view.

etc. etc.

Soon you'll find yourself needing models. Reference the model as you'd like to interact with it from the view. e.g. @articles.each do |article| etc.You'll get an 'undefined method on nil' or similar.

Then you define your model as you'd like to intereact with it in your controller (e.g. @articles = Article.all). Then you'll get an error that your model doesn't exist. Create the model.

Add the attributes to the model that you need in the view.

Repeat the process...

like image 185
Helios de Guerra Avatar answered Sep 23 '26 07:09

Helios de Guerra