- В местах есть_много пива
- Пиво принадлежит_локации
Вот запрос, отправленный от клиента, когда пользователь нажимает на точку 1.
Код: Выделить всё
Started GET "/locations/1/beers.json" for 127.0.0.1 at 2013-03-09 11:26:16 -0700
Processing by BeersController#index as JSON
Parameters: {"location_id"=>"1"}
Beer Load (0.1ms) SELECT "beers".* FROM "beers"
Completed 200 OK in 12ms (Views: 1.8ms | ActiveRecord: 0.4ms)
Код: Выделить всё
class BeersController < ApplicationController
def index
@beers = Beer.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @beers }
end
end
До сих пор я пробовал :
Код: Выделить всё
class BeersController < ApplicationController
def index
@beers = Beer.find(params[:location_id])
respond_to do |format|
format.html # index.html.erb
format.json { render json: @beers }
end
end
Код: Выделить всё
Started GET "/locations/1/beers.json" for 127.0.0.1 at 2013-03-09 11:19:35 -0700
Processing by BeersController#index as JSON
Parameters: {"location_id"=>"1"}
Beer Load (0.1ms) SELECT "beers".* FROM "beers" WHERE "beers"."id" = ? LIMIT 1 [["id", "1"]]
Completed 200 OK in 2ms (Views: 0.6ms | ActiveRecord: 0.1ms)
Код: Выделить всё
Beer Load (0.1ms) SELECT "beers".* FROM "beers" WHERE "beers"."location_id" = ? LIMIT 1 [["location_id", "1"]Как я могу изменить свой контроллер, чтобы он отвечал пивом, принадлежащим только идентификатору location_id, отправляемому клиентом?
Подробнее здесь: https://stackoverflow.com/questions/153 ... parameters
Мобильная версия