我无法通过我的关联访问模型。我有三个模型:
用户.rb
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable
has_one :profile
has_many :posts
attr_accessible :email, :password, :password_confirmation, :remember_me
end
简介.rb
class Profile < ActiveRecord::Base
belongs_to :user, :dependent => :destroy
has_many :posts
attr_accessible :currentlatitude, :currentlongitude, :forename, :surname, :profpicture, :notes
end
Post.rb
class Post < ActiveRecord::Base
...
attr_accessible :title, :body, :tag_list, :blogger_id, :coverphoto, :locations_attributes
belongs_to :user, :polymorphic => true
has_and_belongs_to_many :locations
has_one :profile
end
我想在帖子标题旁边的帖子索引视图中显示 Profile.forename,但是当我尝试时;
<%= post.profile.forename %>
我只是收到以下错误:
SQLite3::SQLException: no such column: profiles.post_id: SELECT "profiles".* FROM "profiles" WHERE "profiles"."post_id" = 56 LIMIT 1
我认为上述关联有问题,知道吗?