오류없이 콘솔에서이 API 호출에로드 된 shopping_list_products에 액세스 할 수 있습니다. 클래스에 대해 정의되지 않은 메소드 'id'가 콘솔을로드합니다.
나는 그러나, API에 500를 얻을 :ActionView::Template::Error (undefined method `id' for #<Class:0x007f6cca7e1dd0>):
2015-01-26T23:51:07.608697+00:00 app[web.1]: 1: collection :@shopping_list_products
2015-01-26T23:51:07.608699+00:00 app[web.1]: 2: extends 'api/v1/shopping_list_products/_show'
index.json.rabl :
collection :@shopping_list_products
extends 'api/v1/shopping_list_products/_show'
show.json.rabl :
object :@shopping_list_product
extends 'api/v1/shopping_list_products/_show'
_show.json을 .rabl :
object :shopping_list_product
attribute(:id, :if => lambda { |m| m.id })
attributes :shopping_list_retailer_id, :product_id, ...
... more attributes
child :product, partial: 'api/v1/products/_show'
child :product_category, partial: 'api/v1/product_categories/_show'
node(:url) do |shopping_list_product|
api_v1_schedule_requisition_plan_shopping_list_shopping_list_retailer_shopping_list_product_path(@schedule, @shopping_list_retailer, shopping_list_product, format: :json)
end
EDIT : id 속성을 제거한 후 다음 오류 인 "Class :에 대해 정의되지 않은 메소드 shopping_list_retailer_id"가 표시되었습니다. 왜 이런 일이 일어나는 걸까요?
편집 : 나는 잘 작동
@shopping_list_retailer.shopping_list_products
를 반환 있는지 찾을 수 그것은 .. 컨트롤러에서 호출 내 코드입니다.
하지만 대신 이렇게 :
api :GET, '/schedule/:schedule_id/requisition_plan/shopping_list/shopping_list_retailers/:shopping_list_retailer_id/shopping_list_products', 'List all shopping list products for Shopping List for Requisition Plans for Schedule in the database'
param :query, String, desc: "Scoped_search style query string"
def index
@shopping_list_products = ShoppingListProductsIndexQuery.new(@shopping_list_retailer, params[:query]).shopping_list_products
end
class ShoppingListProductsIndexQuery
attr_reader :shopping_list_retailer, :query
def initialize(shopping_list_retailer, query)
@shopping_list_retailer = shopping_list_retailer
@query = query
end
def shopping_list_products
@shopping_list_retailer.shopping_list_products.ordered_by_product_category_type_and_product_category_name_and_product_name.search_for(query)
end
end
아직도 혼란 클래스에 대한 정의되지 않은 메서드 ID는 rabl보기에 명중 이유.
같은 문제로 사용될 때이 같은
여전히 무시됩니다 필요가 없습니다. – quantumpotato