実現したいこと
showアクションに行けるようにしたい
発生している問題•エラーメッセージ
該当するコントローラーとルーティングソースコード
(routes.rb) Rails.application.routes.draw do devise_for :users root to: 'top#index' resources :rock_information do resources :rock_task, only: [:new, :create, :show] collection do get 'search' end end resources :gym_information, only: %i[index new create show edit update]do collection do get 'search' end end resources :group, only: %i[index] resources :orders, only:[:new,:create] resources :users, only: :show end
(rock_task_controller.rb) class RockTaskController < ApplicationController before_action :authenticate_user!, only: [:new, :create] def show @rocks = RockInformation.find(params[:id]) @task = RockTask.find(params[:id]) end end
(rock_information_controller.rb) before_action :set_rock_information, only[:show] def show @task = RockTask.new @tasks = @rock.rock_tasks.includes(:user) end private def set_rock_information @rock = RockInformation.find(params[:id]) end end
該当するビューファイル
(views/rock_information/show.html.erb) <div class="contents row"> <ul class = "gym-lists"> <% @tasks.each do |task| %> <%= link_to rock_information_rock_task_path(task.id) do%> <li class= "list"> <% task.images.each do |image| %> <%= image_tag image%> <%= task.name%> <%= task.rock_task_grade.name%> <%= task.other%> <% end %> </li> <% end %> <% end %> </ul> </div>
#試したこと
rails routesで正しくパスが指定できているか確認したが自分ではあっていると思った
(rails routesの結果) root GET / top#index rock_information_rock_task_index GET /rock_information/:rock_information_id/rock_task(.:format) rock_task#index POST /rock_information/:rock_information_id/rock_task(.:format) rock_task#create new_rock_information_rock_task GET /rock_information/:rock_information_id/rock_task/new(.:format) rock_task#new rock_information_rock_task GET /rock_information/:rock_information_id/rock_task/:id(.:format) rock_task#show search_rock_information_index GET /rock_information/search(.:format) rock_information#search rock_information_index GET /rock_information(.:format) rock_information#index POST /rock_information(.:format) rock_information#create new_rock_information GET /rock_information/new(.:format) rock_information#new edit_rock_information GET /rock_information/:id/edit(.:format) rock_information#edit rock_information GET /rock_information/:id(.:format) rock_information#show PATCH /rock_information/:id(.:format) rock_information#update PUT /rock_information/:id(.:format) rock_information#update DELETE /rock_information/:id(.:format) rock_information#destroy
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。