2017-05-03 6 views
0

rake db:seed私は通常動作しますが、現在は失敗しています。Railsシードの移行がエラーで停止しています。ActiveModel :: UnknownAttributeError

ここにエラーとコードがあります。

私のエラーログ: enter image description here

User.rb:

class User < ApplicationRecord 
cattr_accessor :current_user   
belongs_to :highschool, optional: true 
end 

高校の移行:ユーザーへ

class CreateHighschools < ActiveRecord::Migration[5.0] 
def change 
create_table :highschools do |t| 
    t.string :secondaryschool 

    t.timestamps 
end 
end 
end 

高校の移行参照:

class AddHighschoolRefToUsers < ActiveRecord::Migration[5.0] 
def change 
add_reference :users, :highschools, foreign_key: true 
end 
end 

Highschool.rb:

class Highschool < ApplicationRecord 
has_many :users 
end 

Highschools_controller.rb:

class HighschoolsController < ApplicationController 
before_action :authenticate_user!, only: [:new, :create] 
def create 
    @highschool = Highschool.new(highschool_params) 
    if @highschool.save 
    render json: @highschool 
else 
    render json: {errors: @highschool.errors.full_messages} 
end 
end 
private 
    def highschool_params 
params.require(:highschool).permit(:secondaryschool) 
end 
end 

Schema.rb:

create_table "highschools", force: :cascade do |t| 
t.string "secondaryschool" 
t.datetime "created_at",  null: false 
t.datetime "updated_at",  null: false 
    end 

Seeds.rb:

Highschool.destroy_all 
special = Highschool.create!(Secondaryschool: "Stuyvesant High School") 
special2 = Highschool.create!(Secondaryschool: "Brooklyn Tech") 
special3 = Highschool.create!(Secondaryschool: "Bronx Science") 
+1

エラー、データ、コードなどの情報に画像を使用しないでください。リンクは、質問に不可欠な情報を削除したり壊したりする可能性があります。また、情報を再利用することはできません。しばしば、エラーの一部を検索します。そのため、コピー/ペーストではなく入力する必要があります。また、検索エンジンは画像をインデックスに登録することができないため、同じ問題のヘルプを検索するときに他の人があなたの質問を見つけるのが難しくなります。覚えておいても、同じ質問をして将来的に助けてくれるのと同じくらい、あなたを助ける答えはそれほどありません。 –

+0

偉大な点、私はそれを行うことを確認します@theTinMan – Omar

答えて

2

は、タイプミスをTheresの。

special = Highschool.create!(secondaryschool: "Stuyvesant High School") 
special2 = Highschool.create!(secondaryschool: "Brooklyn Tech") 
special3 = Highschool.create!(secondaryschool: "Bronx Science") 
+0

大文字の "S"はそれを捨てているものですか? – Omar

+0

yup!あなたがログで見ることができるように – uday

+0

うわー!とてもありがとうございました! – Omar

関連する問題