rails_動的なroutes_urlの設定

前提

Ruby初学者です。3か月ほど独学で学習している者です。
現在イベント管理ツールを開発中です。
deviceのログイン機能を利用しチームごとに管理できるアプリを開発中

共有URLでログインしていないユーザーも登録できるようにしましたが
URLの生成時にチームの名前をURLに取り入れたい状況です。

下記サイトを参考に動的なURLの実装を試みておりますが、実装できない状況です。
https://ac-creative-lab.net/way_to_develop_routing_with_dynamic_path/

参考サイト通りに調整しましたが、エラーが表示される状況です。

ActionController::UrlGenerationError (No route matches {:action=>"index", :controller=>"schedules"}, missing required keys: [:teamcores_teamname]):

ご回答のほどよろしくお願い致します

実現したいこと

teamcore.rb(モデル)にある値をURLに表示させたい。

発生している問題・エラーメッセージ

ActionController::UrlGenerationError (No route matches {:action=>"index", :controller=>"schedules"}, missing required keys: [:teamcores_teamname]):

該当のソースコード

routes.rb

Rails.application.routes.draw do get 'kiyaku/index' get 'top', to: 'home#top', as: :top root to:'home#index' namespace :admin do resources :users end #root 'schedules#show' # get "/" => "schedules#index" get 'login', to: 'home#index' resources :team resources :answers scope '/:teamcore_teamname' do resources :schedules, only: [:index, :show, :new, :create, :destroy] end #resources :schedules resources :kiyaku # registrations_controller.rbを有効にします。 devise_for :users, controllers: { registrations: 'users/registrations' } devise_scope :user do post 'users/sign_up/confirm', to: 'users/registrations#confirm' get 'users/sign_up/email_notice', to: 'users/registrations#email_notice' get 'users/sign_up/complete', to: 'users/registrations#complete' end # お問い合わせフォーム resources :contacts, only: [:new, :create] post 'contacts/confirm', to: 'contacts#confirm', as: 'confirm' post 'contacts/back', to: 'contacts#back', as: 'back' get 'done', to: 'contacts#done', as: 'done' # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html get '*path', controller: 'application', action: 'render_404' end

teamcore.rb(モデル)

class Teamcore < ApplicationRecord validates_uniqueness_of :access_token validates_presence_of :access_token after_initialize :set_access_token, if: :new_record? validates :teamname, presence: true belongs_to :user,dependent: :destroy has_many :schedules, dependent: :destroy #private def set_access_token self.access_token = self.access_token.blank? ? generate_access_token : self.access_token end def generate_access_token tmp_token = SecureRandom.urlsafe_base64(6) self.class.where(:access_token => tmp_token).blank? ? tmp_token : generate_access_token end end

試したこと

keyの設定がないとエラーが表示されたので下記の参考サイトを試しました。
https://teratail.com/questions/244048

ActionView::Template::Error (No route matches....missing required keys: [:id]):と
表示されました。

補足情報(FW/ツールのバージョンなど)

ここにより詳細な情報を記載してください。

コメントを投稿

0 コメント