У меня запущено приложение. Я хочу создать миграцию UserNotifications, которая принадлежит пользователю. Но миграция продолжает давать ошибки.
class CreateUserNotifications < ActiveRecord::Migration
def self.up
create_table :user_notifications do |t|
t.integer :user_id
t.boolean :notify_news, :default => true
t.boolean :notify_research, :default => true
t.timestamps
end
# Ensure Existing users have a notification setting
User.all.each do |u|
UserNotification.create_by_user_id(u.id)
user.save
end
add_index :user_notifications, :user_id
end
def self.down
drop_table :user_notifications
end
end
Чтобы убедиться, что я прошу четкий вопрос, вот информация о модели:
class User < ActiveRecord::Base
has_one :user_notification, :dependent => :destroy
class UserNotification < ActiveRecord::Base
belongs_to :user
ОШИБКА:
$ rake db:migrate
(in /Users/bhellman/Sites/cline)
== CreateUserNotifications: migrating ========================================
-- create_table(:user_notifications)
NOTICE: CREATE TABLE will create implicit sequence "user_notifications_id_seq" for serial column "user_notifications.id"
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "user_notifications_pkey" for table "user_notifications"
-> 0.2942s
rake aborted!
An error has occurred, this and all later migrations canceled:
undefined method `create_by_user_id' for UserNotification(Table doesn't exist):Class
Спасибо, что заглянули