#active record
11 posts tagged active record. Clear filter
-
Rails Find All by Birthday: How to Find Upcoming Birthdays with ActiveRecord
There are a few ways to solve this problem. However, I think the easiest is to cache the day of the year that the user is born on as an integer. If stored alongside the timestamp we can quickly get...
-
Reusing Scopes (Formerly Named_scope) In Rails 3
You can easily chain scopes together in your models. class Article < ActiveRecord::Base scope :ordered, order('position ASC') scope :published, ordered.where('published = ?', true) scope...
-
Select Distinct in Rails with Active Record
-
Load All ActiveRecord::Base Model Classes in Rails Application
Here is a simple rake task which will instantiate all of your Active Record models, provided that they are located in the RAILS\ROOT/app/models directory. Interestingly, all plugin models are...
-
Rake DB Everything, Dump, Destroy, Create, Load
I'm a big fan of the yaml\db plugin. But I don't like running rake db:data:load, only to find that my db columns mismatch my model attributes, thus aborting the data import task. To quickly...
-
Active Record Find Methods
Active Record find methods for selecting range from http://charlesmaxwood.com/notes-from-reading-activerecordbase/
-
Change database column names for form validations in Rails
When you use validations in Rails, db column names are used as 'keys' for error messages. This is usually the preferred way to go about it because this maps nicely to the form fields. However, if...
-
Rails Plugin Acts as Taggable on Steriods
You can download it here http://github.com/suitmymind/acts-as-taggable-on-steroids as well as read usage info (which is for the most part reprinted here). Then in your model And usage is as follows...
-
Descending Sort By in Model For Active Record Hash on Created_at attribute
If you have a couple collections from the database and you want to sort it without the help of Active Record, take a look at the sort\by method on Array type. I've used this before when I have a...
-
Output Logger and SQL to the Rails Console in Development Mode
If you want to take a look at the SQL being generated by active record while your using the console, you can either type this into the console when it loads Or you can add it to your environment so...
-
Acts_as_versioned Rails Plugin
Versioning models with the acts\as\versioned plugin In your model In db/migrate/\\\\\create\posts.rb Migrate your db Usage \Quick Note If you want to revert to an older version in a controller or...