27
这里是我的控制器协会命名未发现可能拼错的问题轨协会
@post = Post.joins(:customers).select("customers.*,posts.*").find params[:id]
我的岗位模型
belongs_to :customer
我的客户模型
has_many :posts
,我得到错误的
Association named 'customers' was not found on Post; perhaps you misspelled it?
这是我的控制器输出:
Processing by PostsController#show as */*
Parameters: {"id"=>"6"}
Post Load (0.5ms) SELECT "posts".* FROM "posts" WHERE "posts"."id" = $1 LIMIT 1 [["id", "6"]]
Completed 500 Internal Server Error in 113ms
ActiveRecord::ConfigurationError (Association named 'customers' was not found on Post; perhaps you misspelled it?):
app/controllers/posts_controller.rb:16:in `show'
YAE其工作。 – overflow
好吧,现在我需要另一个澄清。我在两桌都有'created_at'。我需要两个日期(即)'注册日期'和'发布日期'我怎样才能得到它。 – overflow
这是另一个与这个不相关的问题,如果你想在Stackoverflow上创建另一个问题。 (但通常使用'post.created_at'来获取Post实例的created_at值) – MrYoshiji