私は最初のAPIを構築し、期待通りに動作しますが、私の要求で結果を制限できない理由を理解していません。私が対象としたすべての検索では、以下にリストされているのと同じ制限パラメータが一覧表示されます。私のapiはRails 5の中にGrapeを使って作られています。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
@mark私のオリジナルのスレッドを編集して、私のapiファイルとコントローラーファイルを追加しました。ありがとうございました。 –