【发布时间】:2021-02-11 23:30:39
【问题描述】:
我试图让用户通过 API 进行搜索,但出现以下错误:
“找不到没有 ID 的游戏”
这是我的控制器:
class GamesController < ApplicationController
def index
@games = Game.all
end
def create
@game = Game.new(game_params)
end
def show
end
def search
@games = Game.find(params[:id])
game = GiantBomb::Game.name
end
def new
@game = Game.new
end
def edit
end
private
def game_params
params.require(:game).permit(:name)
end
end
我的路线:
Rails.application.routes.draw do
devise_for :users
resources :games
root to: 'pages#home'
post '/search', to: 'games#search', as: :search
end
我认为我的搜索表单不太可能导致错误,但无论如何:
<div class="col-md-12">
<%= form_tag search_path class: "row", method: :get do %>
<div class="col-12 col-sm pr-sm-0">
<%= text_field_tag :game,
params[:game],
class: "form-control input-lg",
id: "typed-text" %>
</div>
<div class="input-group-btn ml-3">
<%= submit_tag "Search", class: "btn btn-primary" %>
</div>
<% end %>
我是否需要更改我的路由,或者我编写控制器的方式有问题?
【问题讨论】:
标签: ruby-on-rails api model-view-controller