Ruby Error未初始化的常量

时间:2015-04-16 10:07:38

标签: ruby-on-rails ruby

我刚开始使用Ruby on rails并遵循https://mackenziechild.me/12-in-12/3/

的教程

在某些时候我有错误

    Showing /home/ubuntu/workspace/app/views/cities/_form.html.haml where line #26 raised: uninitialized constant City::Direction

并指出:

    .col-md-6
               %h3 How to get There ?
               #getthere
                   = f.simple_fields_for :directions do |direction|
                       = render 'direction_fields', :f => direction
                   .links
                       = link_to_add_association 'Add Directions', f, :directions, class: "btn btn-default add-button"  

我不知道在哪里看,据我所知,我的数据库创建得很好。有人可以帮我吗?

我有这个数据库

    class CreateDirections < ActiveRecord::Migration
      def change
        create_table :directions do |t|
          t.text :getthere
          t.belongs_to :city, index: true

          t.timestamps
        end
      end
    end

和这个

    class CreateCities < ActiveRecord::Migration
      def change
        create_table :cities do |t|
          t.string :title
          t.text :description
          t.integer :user_id

          t.timestamps
        end
      end
    end

和这个城市模型

 class City < ActiveRecord::Base
    has_many :infos
    has_many :directions

    accepts_nested_attributes_for :infos, reject_if: proc { |attributes| attributes['information'].blank? },
    allow_destroy: true
    accepts_nested_attributes_for :directions, reject_if: proc { |attributes| attributes['getthere'].blank? },
    allow_destroy: true

    validates :title, :description, :image, presence: true
    has_attached_file :image, :styles => { :medium => "163x163#"}
    validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/

 end

0 个答案:

没有答案