我试图序列化嵌套集合。我有一个带图像的产品。但是,当我尝试使用has_many
或显式方法在我的产品序列化程序中定义images
属性时,我得到:
wrong number of arguments (0 for 1)
我本可以发誓这是可行的。我做错了吗?
这是我的代码:
class Api::V1::ProductSerializer < ActiveModel::Serializer
attributes :id, :sku, :name, :description, :images
def images
object.images
end
end
完全回溯
Started GET "/api/v1/products" for 10.0.2.2 at 2015-03-02 23:12:34 +0000
Processing by Api::V1::ProductsController#index as HTML
User Load (0.7ms) SELECT "users".* FROM "users" INNER JOIN "tenant_users" ON "tenant_users"."user_id" = "users"."id" WHERE "tenant_users"."tenant_id" = 1 AND "users"."authentication_token" = 'pGJE5UWrxzJTEPxMyiez' ORDER BY "users"."id" ASC LIMIT 1
(0.3ms) BEGIN
SQL (0.4ms) UPDATE "users" SET "current_sign_in_at" = $1, "last_sign_in_at" = $2, "sign_in_count" = $3, "updated_at" = $4 WHERE "users"."id" = 1 [["current_sign_in_at", "2015-03-02 23:12:34.913333"], ["last_sign_in_at", "2015-03-02 23:12:33.754114"], ["sign_in_count", 171], ["updated_at", "2015-03-02 23:12:34.914298"]]
(0.7ms) COMMIT
Product Load (0.4ms) SELECT "products".* FROM "products" WHERE "products"."tenant_id" = 1
Attachinary::File Load (0.5ms) SELECT "attachinary_files".* FROM "attachinary_files" WHERE "attachinary_files"."attachinariable_id" = $1 AND "attachinary_files"."attachinariable_type" = $2 AND "attachinary_files"."scope" = 'images' [["attachinariable_id", 1], ["attachinariable_type", "Product"]]
Completed 500 Internal Server Error in 19ms
ArgumentError (wrong number of arguments (0 for 1)):
app/controllers/api/v1/products_controller.rb:4:in `index'
app/controllers/concerns/api/landlord.rb:13:in `require_tenant!'
Rendered /usr/local/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/actionpack-4.1.8/lib/action_dispatch/middleware/templates/rescues/_source.erb (0.4ms)
Rendered /usr/local/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/actionpack-4.1.8/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.1ms)
Rendered /usr/local/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/actionpack-4.1.8/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (0.1ms)
Rendered /usr/local/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/actionpack-4.1.8/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (11.7ms)