Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 未定义的方法`表名称';你的意思是什么?表\u名称\u前缀_Ruby On Rails_Ruby_Api - Fatal编程技术网

Ruby on rails 未定义的方法`表名称';你的意思是什么?表\u名称\u前缀

Ruby on rails 未定义的方法`表名称';你的意思是什么?表\u名称\u前缀,ruby-on-rails,ruby,api,Ruby On Rails,Ruby,Api,我正在使用构建一个API。 我用于正确显示序列化数组 # app/controllers/api/v1/posts_controller.rb class Api::V1::PostsController < Api::V1::BaseController include ActiveHashRelation def index posts = apply_filters(Post::Post.all, params) render json: posts, ea

我正在使用构建一个API。 我用于正确显示序列化数组

# app/controllers/api/v1/posts_controller.rb
class Api::V1::PostsController < Api::V1::BaseController
  include ActiveHashRelation
  def index
    posts = apply_filters(Post::Post.all, params)

    render json: posts, each_serializer: Api::V1::PostSerializer
  end
end

我认为这是因为ActiveHashrelation,因为当我写
posts=Post::Post.all
时,它工作了。但是我不能过滤数组。

有一个名为
Post
的模型和一个名为
Post
的模块会引起麻烦。如果你能给他们起一个稍微不同的名字,这将有助于避免混淆
Post::Post
::Post
。很可能您正在使用
Post
某个您打算使用
Post::Post
的地方。我会这样做。非常感谢。
# app/models/post/post.rb
class Post::Post < ActiveRecord::Base
  validates_presence_of :body
end

# app/models/post.rb
module Post
  def self.table_name_prefix
     'post_'
  end
end