开发者

A seasoned programmer, confused on how to start coding a rails app from scratch

开发者 https://www.devze.com 2023-04-12 10:15 出处:网络
I have been involved with several ruby on rails projects in the past, but I joined in those projects with a completely built rails app, complete with spec tests, factories, models, views, controllers

I have been involved with several ruby on rails projects in the past, but I joined in those projects with a completely built rails app, complete with spec tests, factories, models, views, controllers and some custom libraries. I did hundred开发者_如何转开发s of commits to fix assigned tickets in those projects, and I know the Rails MVC architecture well.

But now is the time that I need to create a Rails app from scratch, on my own, and despite my rails experience, I don't have the confidence to start.

My biggest problem is, how to decide the controllers that I will create, what is the purpose of the controllers that I create, the entire design of the web app, there's so many things that is running on my head right now, and I just couldn't sort it out.

Does anyone has the same situation, or have encountered the same problem before like me?


When starting a new application, I usually sketch out (on paper) a really high-level overview of what I think the core models of the app are going to be, and how they relate to one another. Obviously these will likely change as your application evolves during the development process, but it's a good place to start.

Then, from that pool, I identify the model which is most 'core' to the application's purpose - and I start by generating that with rails g model ModelName. For example: I was recently working on a hotel directory and started with the Hotel model.

Then I apply some pretty basic TDD methodologies and start writing the spec for the unit test for that model, run the tests, build, write more spec, refactor, etc. As bits fall into place, do a commit and move on. That way, if you go down a wrong path, it's easy to get back to a healthy spot again and you don't have to worry (as much) about making mistakes.

I usually find that by starting with the unit tests for the core models, the rest of your application will naturally evolve out. Once you decide to move onto functional and integration tests you should have a really clear idea about how all the pieces fit together and how your users should 'flow' through your application. This should naturally lead you to develop controllers that fit your different user's scenarios.

Above all, practicing is the best way to get used to starting from scratch. Build some basic apps with really clear outcomes, like a blog or simple scheduling tool. It will help you get used to the process so when you move onto bigger or more abstract applications - you'll be more adept at getting off the ground.


I would start with a tutorial that has you put a small system together from scratch like this:

http://guides.rubyonrails.org/getting_started.html

If you already have everything set up, you can skip to 3.2

Also, make sure you're using version control software and branch/revert often if you don't like the direction it's going (I recommend a distributed version control system like git as they often have better branching/merging)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号