前提
RailsでAPIを利用してサッカー選手を検索できるアプリを作成しています。
search.html.erbを表示させたいがルーティングエラーが出ます。
原因がわからず困っています。宜しくお願いします
実現したいこと
search.html.erbを表示させたいです。
ここに実現したいことを箇条書きで書いてください。
- ▲▲機能を動作するようにする
発生している問題・エラーメッセージ
ターミナルのエラーメッセージです。
Started GET "/players/serach" for ::1 at 2022-11-03 21:36:41 +0900 ActionController::RoutingError (No route matches [GET] "/players/serach"):
実現したいこと
search.html.erbを表示させたいです。
発生している問題・エラーメッセージ
ターミナルのエラーメッセージです。
Started GET "/players/serach" for ::1 at 2022-11-03 21:36:41 +0900 ActionController::RoutingError (No route matches [GET] "/players/serach"):
該当のソースコード
search.html.erb
<%= form_with url: players_search_path, method: :get, local: true do |form| %> <%= form.text_field :season, class: 'form-control', placeholder: '西暦を入力してください(例: 1997)' %> <div class="input-group mb-3"> <%= form.text_field :player_name, class: 'form-control', placeholder: '選手名を入力してください' %> <div class="input-group-append"> <%= f.submit '検索', class: 'btn btn-primary' %> </div> </div> </div> <% end %>
players_controller.rb
class PlayersController < ApplicationController require 'uri' require 'net/http' require 'openssl' require 'json' before_action :set_q, only: [:search] # GET /players or /players.json def index @players = Player.all end def search url = URI('https://api-football-v1.p.rapidapi.com/v3/players?team=85&search=cavani&season=2018') http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Get.new(url) request["x-rapidapi-host"] = 'api-football-v1.p.rapidapi.com' request["x-rapidapi-key"] = 'ENV['API_KEY']' response = http.request(request) puts response.read_body #@q = Player.ransack(params[:q]) #@players = @q.result(distinct: true).includes(:user).order(created_at: :desc).page(params[:page]) #@seasons = @q.result(distinct: true).includes(:user).order(created_at: :desc).page(params[:page]) end private def set_q @q = User.ransack(params[:q]) end # Use callbacks to share common setup or constraints between actions. def set_player @player = Player.find(params[:id]) end # Only allow a list of trusted parameters through. def player_params params.require(:player).permit(:player_name, :season) end def search_params params[:q]&.permit(:player_name, :season) end end
routes.rb
Rails.application.routes.draw do root 'static_pages#top' get 'login', to: 'user_sessions#new' post 'login', to: 'user_sessions#create' delete 'logout', to: 'user_sessions#destroy' resources :users, only: %i(new create) # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html resources :players, only: %i[index] do collection do get 'search' end end end
rails routes
Prefix Verb URI Pattern Controller#Action root GET / static_pages#top login GET /login(.:format) user_sessions#new POST /login(.:format) user_sessions#create logout DELETE /logout(.:format) user_sessions#destroy users POST /users(.:format) users#create new_user GET /users/new(.:format) users#new search_players GET /players/search(.:format) players#search players GET /players(.:format) players#index rails_postmark_inbound_emails POST /rails/action_mailbox/postmark/inbound_emails(.:format) action_mailbox/ingresses/postmark/inbound_emails#create rails_relay_inbound_emails POST /rails/action_mailbox/relay/inbound_emails(.:format) action_mailbox/ingresses/relay/inbound_emails#create rails_sendgrid_inbound_emails POST /rails/action_mailbox/sendgrid/inbound_emails(.:format) action_mailbox/ingresses/sendgrid/inbound_emails#create rails_mandrill_inbound_health_check GET /rails/action_mailbox/mandrill/inbound_emails(.:format) action_mailbox/ingresses/mandrill/inbound_emails#health_check rails_mandrill_inbound_emails POST /rails/action_mailbox/mandrill/inbound_emails(.:format) action_mailbox/ingresses/mandrill/inbound_emails#create rails_mailgun_inbound_emails POST /rails/action_mailbox/mailgun/inbound_emails/mime(.:format) action_mailbox/ingresses/mailgun/inbound_emails#create rails_conductor_inbound_emails GET /rails/conductor/action_mailbox/inbound_emails(.:format) rails/conductor/action_mailbox/inbound_emails#index POST /rails/conductor/action_mailbox/inbound_emails(.:format) rails/conductor/action_mailbox/inbound_emails#create new_rails_conductor_inbound_email GET /rails/conductor/action_mailbox/inbound_emails/new(.:format) rails/conductor/action_mailbox/inbound_emails#new edit_rails_conductor_inbound_email GET /rails/conductor/action_mailbox/inbound_emails/:id/edit(.:format) rails/conductor/action_mailbox/inbound_emails#edit rails_conductor_inbound_email GET /rails/conductor/action_mailbox/inbound_emails/:id(.:format) rails/conductor/action_mailbox/inbound_emails#show PATCH /rails/conductor/action_mailbox/inbound_emails/:id(.:format) rails/conductor/action_mailbox/inbound_emails#update PUT /rails/conductor/action_mailbox/inbound_emails/:id(.:format) rails/conductor/action_mailbox/inbound_emails#update DELETE /rails/conductor/action_mailbox/inbound_emails/:id(.:format) rails/conductor/action_mailbox/inbound_emails#destroy new_rails_conductor_inbound_email_source GET /rails/conductor/action_mailbox/inbound_emails/sources/new(.:format) rails/conductor/action_mailbox/inbound_emails/sources#new rails_conductor_inbound_email_sources POST /rails/conductor/action_mailbox/inbound_emails/sources(.:format) rails/conductor/action_mailbox/inbound_emails/sources#create rails_conductor_inbound_email_reroute POST /rails/conductor/action_mailbox/:inbound_email_id/reroute(.:format) rails/conductor/action_mailbox/reroutes#create rails_service_blob GET /rails/active_storage/blobs/redirect/:signed_id/*filename(.:format) active_storage/blobs/redirect#show rails_service_blob_proxy GET /rails/active_storage/blobs/proxy/:signed_id/*filename(.:format) active_storage/blobs/proxy#show GET /rails/active_storage/blobs/:signed_id/*filename(.:format) active_storage/blobs/redirect#show rails_blob_representation GET /rails/active_storage/representations/redirect/:signed_blob_id/:variation_key/*filename(.:format) active_storage/representations/redirect#show rails_blob_representation_proxy GET /rails/active_storage/representations/proxy/:signed_blob_id/:variation_key/*filename(.:format) active_storage/representations/proxy#show GET /rails/active_storage/representations/:signed_blob_id/:variation_key/*filename(.:format) active_storage/representations/redirect#show rails_disk_service GET /rails/active_storage/disk/:encoded_key/*filename(.:format) active_storage/disk#show update_rails_disk_service PUT /rails/active_storage/disk/:encoded_token(.:format) active_storage/disk#update rails_direct_uploads POST /rails/active_storage/direct_uploads(.:format) active_storage/direct_uploads#create
補足情報(FW/ツールのバージョンなど)
Rails バージョン 6.1.5
宜しくお願いいたします。
回答2件
あなたの回答
tips
プレビュー
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。