Tag: rails

  • Moving Static Files to the Assets Pipeline (upgrading from 3.0 to 3.1+)

    For those who have done the upgrade, this is probably second nature: Recently stumbled upon static files in the public/javascripts directory and wanted to get them moved to the $RAILS_ROOT/app/assets/ directory. This RailsCast, 282 Upgrading to Rails 3.1 provides most of the notes you need on doing this. The first key is to include: config.assets.enabled…

  • Nesting resource routes with alternate scopes and keys + strong parameters.

    DISCLAIMER: This is a contrived example translated from a case where it actually made way more sense to break the familiar nested resource pattern. Also, I haven’t double-checked how Rails’ pluralization rules would affect the naming of any given Species. Say you have a pair of models: class Species # id # latin_name_with_underscores end class…

  • Conditions on a has_many :through and ActiveRecord 4.1 enum

    Say you have a set of models (model names sanitized for generic posting) where the join table in the middle of a has_many :through has an enum that you want to add a filtered association for. class Student < ActiveRecord::Base has_many :student_grades has_many :grades, through: :student_grades end class StudentGrade < ActiveRecord::Base enum approval_status: [:not_reviewed, :rejected,…