Welcome to day 42 of the 49 Days of Ruby! 🎉
Today, we are going to take a quick look at Ruby on Rails. This framework perhaps did more to popularize the Ruby language than anything else. However, as we have seen, it is not the only web framework out there.
Getting Started with Rails
From the command line, you can run rails new my_app
and that will create a new directory called my_app
with all the scaffolding for a Ruby on Rails website.
Then, change into the directory of the app, and run bundle install
and bundle exec rails db:migrate
. This will install the gems for the app, and set up the initial database schema.
Once that is finished, you can run bundle exec rails server
and navigate to http://localhost:3000
in your web browser. You will see something like this:
Rails Architecture
We learned yesterday about how Hanami architects its apps and puts the models, views, and controllers.
In Rails, it is done a little bit different but still operates within the MVC design.
- The Controllers for your app live inside
app/controllers
- The Models for your app live inside
app/models
- The Views for your app live inside
app/views
Rails Generators
Rails ships with interesting things called "generators", which helps you build components of your web app relatively quickly. You can read more about them in the Ruby on Rails Docs for the specifics.
With generators, you can create controllers, models, database tables, and more from your command line.
For the rest of today, play around with Rails! See what you can build and share it with the community.
Come back tomorrow for the next installment of 49 Days of Ruby! You can join the conversation on Twitter with the hashtag #49daysofruby.
Top comments (0)