Rails Best Practices

A collection of tips showing best practices programming on Ruby on Rails.

Overview

– Python vs Ruby and Django vs. Rails

 

Architecture

– Rails application architecture tips

 

Tools

– LiveReload for Rails app (on gist.github.com)

 

Delayed jobs, Sidekiq, Resque, God

– Send asynchronious emails with ActionMailer and Sidekiq

– God + Resque, gist: https://gist.github.com/maxivak/05847dc7f558d5ef282e

 

Deployment

– Deploy a Rails app with Capistrano 3  (Example on Github)

 

Testing

– Run RSpec tests as a Rake task

– Running Selenium tests with Ruby on Centos

– Examples of RSpec tests with Capybara, Selenium, Headless

 

Create own Gems

– Creating your own gems

ActiveAdmin

– Custom controller actions in ActiveAdmin

 

Search

– Solr search engine with Sunspot gem

 

Spree shop

 

Code examples

ActiveRecord, Models:

– update_attribute, update_attributes and update_column

– Get a list of IDs from database

– How to pass multiple attributes to find_or_create_by

– How to determine if a record was created or updated in after_save callback

 

Forms

– custom submit button in simple_form for Bootstrap 3

– Nested Models in one form using Formtastic and Cocoon gems

 

Sessions

– Clear old sessions stored in database

– Sessions do not work in Internet Explorer in Rails

Assets

– Disable logging of asset pipeline messages

– Using CDN with Rails assets

 

Mail

– Send email to multiple recipients

 

Sitemap.xml

* generate-sitemap-xml-for-rails-4-application/ (gist)

 

TinyMCE

– TinyMCE 4 text editor + elFinder file manager

 

 

Misc

– Loading “Seed” Data

– attr_accessor vs attr_accessible

– Link to download an image as attachment in Rails (send_file and remote files)

– Cropping and resizing images using MiniMagick

– Redirect from www to non-www version of site

– Password protecting pages of Rails App

– Custom slugs using gem Slugged

 

 

Countries, Cities

– Select Tag with List of Countries

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>