0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ユーザーごとの投稿一覧を表示させたい

Last updated at Posted at 2021-09-16

患者(user)ごとの記録一覧ostomy(index)を医療者(admin)が見れるようにしたいが、nullデータが持ってこれない

```ruby:Staff/Ostomies.controller.rb class Staff::OstomiesController < ApplicationController before_action :authenticate_staff! def index #患者さんごとのindex @ostomies = Ostomy.where(patient_id: params[:patient_id]) end ```
routes.rb
 namespace :staff do  #医療者のコントローラー内
    :
     resources :ostomies,:only => [:show],:index] do  #患者さんが書いた記録
       resources :comments, only: [:create, :destroy] #記録へのコメント
       resource :favorites, only: [:create, :destroy]  #記録へのいいね
     end
    resources :patients,:except => [:destroy,:new,:create] do
       resources :records,:except => [:destroy]   #患者ごとに記録するためネストさせる
    end
  end

idをurlにぶち込むことでid指定して持ってこれるようになる

 
参照

routes.rb
 namespace :staff do
    get '/ostomies/index/:patient_id',         to: 'ostomies#index', as: 'ostomy_index'
    get '/ostomies/show/:ostomy_id/:patient_id',to: 'ostomies#show', as: 'ostomy_show'
   :
  end
staff_ostomy_index GET  /staff/ostomies/index/:patient_id(.:format) staff/ostomies#index                                             
staff_ostomy_show GET  /staff/ostomies/show/:ostomy_id/:patient_id(.:format)  staff/ostomies#show                                                  

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?