Top "Rails-activerecord" questions

The implementation of object-relational mapping (ORM) using the Active Record pattern in the Ruby on Rails framework.

How to write SQL in a migration in Rails

I have the following SQL which I need to do CREATE TABLE cars_users2 AS SELECT DISTINCT * FROM cars_users; …

sql postgresql ruby-on-rails-3 migration rails-activerecord
Merge arrays in Ruby/Rails

How can I merge two arrays? Something like this: @movie = Movie.first() @options = Movie.order("RANDOM()").first(3).merge(@movie) But …

ruby-on-rails ruby ruby-on-rails-4 orm rails-activerecord
ActiveRecord query through multiple joins

I have a schema like this. managers has_many :emails has_many :stores emails belongs_to :manager stores belongs_to :…

ruby-on-rails-4 rails-activerecord active-record-query
Rolling back a failed Rails migration

How do you roll back a failed rails migration? I would expect that rake db:rollback would undo the failed …

mysql ruby-on-rails rails-activerecord rails-migrations
ActiveRecord::SubclassNotFound: The single-table inheritance mechanism failed to locate the subclass

I'm newbie to Rails. I have two models Category and Product as follows:- class Category < ActiveRecord::Base attr_…

ruby-on-rails inheritance rails-activerecord
Adding parameter to a scope

I have a ActiveRecord query for example like this: @result = stuff.limit(10) where stuff is a active record query with …

ruby-on-rails ruby-on-rails-3.2 rails-activerecord
Rails includes with scope

I have a model called Author. An author has many Articles. Articles have a scope called .published that does: where(…

ruby-on-rails activerecord scope rails-activerecord
Heroku Postgres Error: PGError: ERROR: relation "organizations" does not exist (ActiveRecord::StatementInvalid)

I'm having a problem deploying my Rails app to Heroku, where this error is thrown when trying to access the …

ruby-on-rails postgresql heroku rails-activerecord
Iterating through every record in a database - Ruby on Rails / ActiveRecord

n00b question. I'm trying to loop through every User record in my database. The pseudo code might look a …

ruby-on-rails database loops rails-activerecord
How would one validate the format of an email field in ActiveRecord?

I have a User model in a Rails application which has an email field. Is there a default validation that …

ruby-on-rails rails-activerecord