初学者です。
現在患者情報に基づくカルテを作成できるようなものを実装しています。
患者情報を登録するものを以前実装完了していたのですが、本日確認すると、
NoMethodError in PatientsController#new undefined method `move_to_index' for #<PatientsController:0x00007fb160bb7470>
https://gyazo.com/0f81a1fc738c3ba76d58dd8377736c92
↑Gyazoです
とのエラーが発生していました。
原因が分からず、ターミナルを確認したところ
Completed 500 Internal Server Error
https://gyazo.com/d930e87993100579f7d1e63fa6202673
↑Gyazoです
となっていました。
調べてサーバー上の何らかのエラーからこのような状況になっているということはわかりましたが、手がかりがなく困っています。
このエラーの解決についてご教示いただければと思い、投稿しました。
###ソースコード
patients_controller.rb class PatientsController < ApplicationController before_action :if_not_admin before_action :move_to_index, except: [:index, :show, :search] def new @patient = Patient.new end def create @patient = Patient.new(patient_params) if @patient.save redirect_to root_path else render :new end end def show @patient = Patient.find(params[:id]) end def edit @patient = Patient.find(params[:id]) end def update @patient = Patient.find(params[:id]) if @patient.update(patient_params) redirect_to patient_path else render :edit end end def search @patients = Patient.search(params[:keyword]) end private def patient_params params.require(:patient).permit(:family_name, :first_name, :family_name_kana, :first_name_kana, :birth_date_id, :phone_number) end def if_not_admin redirect_to root_path unless current_user && current_user.admin? end end
patient.rb class Patient < ApplicationRecord has_one :karute has_one :patient_address with_options presence: true do validates :family_name, format: { with: /\A[ぁ-んァ-ン一-龥]/ } validates :first_name, format: { with: /\A[ぁ-んァ-ン一-龥]/ } validates :family_name_kana, format: { with: /\A[ァ-ヶー-]+\z/ } validates :first_name_kana, format: { with: /\A[ァ-ヶー-]+\z/ } validates :birth_date_id validates :phone_number, format: { with: /\A\d{11}\z/ } end def self.search(search) if search != "" Patient.where('family_name LIKE ? OR first_name LIKE ? OR family_name_kana LIKE ? OR first_name_kana LIKE ? OR phone_number LIKE ? ' , "%#{search}%", "%#{search}%", "%#{search}%", "%#{search}%", "%#{search}%") else Patient.all end end end
patients/new.html.erb <h2>患者情報登録</h2> <%= form_for(@patient, url: patients_path) do |f| %> <%= render 'shared/error_messages', model: f.object %> <div class="field"> <%= f.label :family_name %><br /> <%= f.text_field :family_name %> </div> <div class="field"> <%= f.label :first_name %><br /> <%= f.text_field :first_name %> </div> <div class="field"> <%= f.label :family_name_kana %><br /> <%= f.text_field :family_name_kana %> </div> <div class="field"> <%= f.label :first_name_kana %><br /> <%= f.text_field :first_name_kana %> </div> <div class="field"> <%= f.label :birth_date_id %><br /> <div class='form-text-wrap'> <label class="form-text">生年月日</label> <span class="indispensable">必須</span> </div> <div class='input-birth-wrap'> <%= raw sprintf( f.date_select( :birth_date_id, class:'select-birth', id:"birth-date", use_month_numbers: true, prompt:'--', start_year: 1930, end_year: (Time.now.year - 5), date_separator: '%s'), "<p> 年 </p>", "<p> 月 </p>") + "<p> 日 </p>" %> </div> </div> <div class="field"> <%= f.label :phone_number %><br /> <%= f.text_field :phone_number %> </div> <div class="actions"> <%= f.submit "登録" %> </div> <%= link_to '戻る', root_path, class: "root_btn" %> <% end %>
karutes/index.html.erb <%= render "header"%> <div class="admin"> <% if user_signed_in?%> <% if current_user.admin? %> <div class="tab"> <h2>一覧は管理者のみ表示されます</h2> <%= link_to "ログアウト", destroy_user_session_path, method: :delete, class: "log_out_btn" %> <%= link_to '患者登録', new_patient_path, class: "admin_btn" %> </div> <div class="karute_user"> <h2>患者カルテ一覧</h2> <%= form_with(url: search_patients_path, local: true, method: :get, class: "search-form") do |form| %> <%= form.text_field :keyword, placeholder: "投稿を検索する", class: "search-input" %> <%= form.submit "検索", class: "search-btn" %> <% end %> <ul class='user_list'> <% @patients.each do |patient| %> <li class='list'> <%= link_to patient_path(patient.id), method: :get do %> <%= patient.family_name %> <%= patient.first_name %> <% end %> </li> <% end %> </ul> </div> <% else %> <%= link_to "ログアウト", destroy_user_session_path, method: :delete, class: "log_out_btn" %> <% end %> <% end %> </div>
routes.rb Rails.application.routes.draw do devise_for :users, controllers: { registrations: 'users/registrations' } devise_scope :user do get 'addresses', to: 'users/registrations#new_address' post 'addresses', to: 'users/registrations#create_address' end root to: "karutes#index" resources :restaurants, only: [:show] resources :patients, only: [:new, :create, :show, :edit, :update] do resources :patient_addresses, shallow: true resources :karutes, shallow: true collection do get 'search' end end resources :menus, only: [:index] resources :bulogs, only: [:index] resources :accesses, only: [:index] end
rails routes root GET / karutes#index restaurant GET /restaurants/:id(.:format) restaurants#show patient_patient_addresses GET /patients/:patient_id/patient_addresses(.:format) patient_addresses#index POST /patients/:patient_id/patient_addresses(.:format) patient_addresses#create new_patient_patient_address GET /patients/:patient_id/patient_addresses/new(.:format) patient_addresses#new edit_patient_address GET /patient_addresses/:id/edit(.:format) patient_addresses#edit patient_address GET /patient_addresses/:id(.:format) patient_addresses#show PATCH /patient_addresses/:id(.:format) patient_addresses#update PUT /patient_addresses/:id(.:format) patient_addresses#update DELETE /patient_addresses/:id(.:format) patient_addresses#destroy patient_karutes GET /patients/:patient_id/karutes(.:format) karutes#index POST /patients/:patient_id/karutes(.:format) karutes#create new_patient_karute GET /patients/:patient_id/karutes/new(.:format) karutes#new edit_karute GET /karutes/:id/edit(.:format) karutes#edit karute GET /karutes/:id(.:format) karutes#show PATCH /karutes/:id(.:format) karutes#update PUT /karutes/:id(.:format) karutes#update DELETE /karutes/:id(.:format) karutes#destroy search_patients GET /patients/search(.:format) patients#search patients POST /patients(.:format) patients#create new_patient GET /patients/new(.:format) patients#new edit_patient GET /patients/:id/edit(.:format) patients#edit patient GET /patients/:id(.:format) patients#show PATCH /patients/:id(.:format) patients#update PUT /patients/:id(.:format) patients#update
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。