Rails conventions

May 10, 06:25 PM

I’ve just been starting on Rails again and am bombarded with the amount of idiomatic usage arising out of “convention over configuration” philosophy of rails. The problem is that it might be hard to even recognize and look for this idioms online since you don’t know exactly what you’re looking for. I am compiling a list of idioms as and when I encounter them for reference.

Routing

Creating paths and urls from objects

This is the full syntax:

<%= link_to "Ad details", url_for(@obj) %>

But rails lets you ignore the url_for when using with helpers like link_to and redirect_to, so this is common:

<%= link_to "Ad details", @obj %>

Reference: Rails Routing Guide

Layouts and Rendering

Embedded Ruby tags

Tags beginning with <%= evaluate the expression they contain and insert them into the document while tags without the = only execute the expression but don’t insert the results into the document.

Reference: Smashing magazine guide


Rahul Jha

,

---

Comment

  1. I am sure that such conversations are very much helpful and they can share new information with many people. I believe that writing of classy resumes can help us in job searching

    classyresumewriter.com/about_us · Mar 19, 06:49 PM · #

  2. Thank you for making a list of these idioms, I find it very helpful for my work. I’ve been looking for it everywhere and finally found here. You are my saviour.

    http://custom-writing.services/ · Jun 6, 08:49 PM · #

 
---