Express yourself in Ruby on Rails!

Welcome to the world of Ruby on Rails development!

As you probably already know, Rails is the most powerful framework for web applications!

Remember! Ruby on Rails is a framework, not a language. Probably you are wondering what does it exactly mean…

So Ruby on Rails is a set of Ruby code libraries. That means that someone wrote for us the code, what do a lot of things for us. You can find here information about what exactly Rails is doing for us!

In Rails, you find yourself looking at controllers, views, and models for your database.

To reduce the need for heavy configuration, Rails implements rules to ease up working with the application. You may define your own rules but for the beginning (and for later on) it’s a good idea to stick to conventions that Rails offers.

These conventions will speed up development, keep your code concise and readable, and allow you easy navigation inside your application.

But hey! Ruby is smart and some code you can write in your own favourite way to achieve the same goal. Look below and choose your favourite way!

Example with command

Commands below are doing the same thing. You can run the migration and seed your database in 2 ways:

~/…your_name/file_name/webapp // ♥ > rails db:migrate db:seed


~/…your_name/file_name/webapp // ♥ > rake db:migrate db:seed

Why? So rails need to call rake to run that migration and seed database.

Example with form

During creating every form, form_for or form_with etc. you can express your style by named the label. You can use:

symbol of the attribute

<%= form_for(@blogger) do |f| %><%= f.label :name %><%= f.text_field :name %><% end %>

or put the words what you would like to see in quotes, double or single. Choose your style!

<%= form_for(@blogger) do |f| %><%= f.label 'Name' %><%= f.text_field :name %><% end %>

Example with method

This example, you may remember from learning Ruby’s fundamental. But it’s good to remind yourself of that way as well!

<ul><% @user.festivals.each |festival| do %><li><%=>></li><% end %></ul>


<ul><% for festival in @user.festivals %><li><%=>></li><% end %></ul>

Example with redirect_to with single object

redirect_to blogger_path( blogger_path(@blogger)redirect_to blogger_path(blogger)redirect_to @bloggerredirect_to 'bloggers/:id'

Example with redirect_to with all objects

redirect_to bloggers_path
redirect_to '/bloggers'

Example with redirect_to with new object path

redirect_to '/bloggers/new'
redirect_to new_blogger_path

You can use those examples for edit route, and your own route!!!

I hope that article will help you find your style!

Happy coding!