내 첫 API를 빌드했는데 예상대로 작동하지만 요청한 결과를 제한 할 수없는 이유를 이해하는 데 어려움을 겪고 있습니다. 주제 목록에서 본 모든 검색은 아래에 나열된 것과 같은 제한 매개 변수를 나열합니다. 내 api는 Rails 5 안에 포도로 만들어졌습니다. 내가 뭘 잘못하고 있는지 아이디어가 있습니까?get 요청의 제한 매개 변수가 Rails 5에서 작동하지 않습니다. Grape Api
https://www.soledadmemorial.com/api/v1/plaques?limit=10
컨트롤러/API/V1/plaques.rb
module API
module V1
class Plaques < Grape::API
include API::V1::Defaults
resource :plaques do
desc 'Return all Plaques'
get '', root: :plaques do
Plaque.all
end
desc 'Return a Plaque'
params do
requires :id, type: String, desc: 'ID of Plaque'
end
get ':id', root: 'plaque' do
Plaque.where(id: permitted_params[:id]).first!
end
end
end
end
end
나는 100 % 확실하지가 일어나고있어 행동
class PlaquesController < ApplicationController
before_action :authenticate_user!, :except => [:index, :show]
before_action :set_plaque, only: [:show, :edit, :update, :destroy]
# GET /plaques
# GET /plaques.json
def index
@plaquelist = Plaque.search(params[:search]).paginate(:per_page => 10, :page => params[:page])
@plaques = Plaque.all
end
# GET /plaques/1
# GET /plaques/1.json
def show
@plaques = Plaque.all
end
# GET /plaques/new
def new
@plaque = Plaque.new
end
# GET /plaques/1/edit
def edit
end
# POST /plaques
# POST /plaques.json
def create
@plaque = Plaque.new(plaque_params)
respond_to do |format|
if @plaque.save
format.html { redirect_to @plaque, notice: 'Plaque was successfully created.' }
format.json { render :show, status: :created, location: @plaque }
else
format.html { render :new }
format.json { render json: @plaque.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /plaques/1
# PATCH/PUT /plaques/1.json
def update
respond_to do |format|
if @plaque.update(plaque_params)
format.html { redirect_to @plaque, notice: 'Plaque was successfully updated.' }
format.json { render :show, status: :ok, location: @plaque }
else
format.html { render :edit }
format.json { render json: @plaque.errors, status: :unprocessable_entity }
end
end
end
# DELETE /plaques/1
# DELETE /plaques/1.json
def destroy
@plaque.destroy
respond_to do |format|
format.html { redirect_to plaques_url, notice: 'Plaque was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_plaque
@plaque = Plaque.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def plaque_params
params.require(:plaque).permit(
:veteran_war,
:veteran_biography,
:veteran_first,
:veteran_last,
:veteran_display_name,
:group_type,
:veteran_nickname,
:group_name,
:veteran_middle,
:veteran_rank,
:veteran_branch,
:grid, :wall,
:direction,
:row,
:plaque_num,
:image,
:search
)
end
end
당신이 컨트롤러에서 PARAMS를 처리하는 코드를 추가 했습니까? 컨트롤러 액션을 게시 할 수 있습니까 – Mark
@marker 원래의 스레드를 편집하여 API 파일과 API 파일을 포함 시켰습니다. 고맙습니다. –