请告诉我为什么会出现此错误
No route matches {:action=>"show51", :controller=>"patients"}
在select51中搜索后,我没有获得index51中的患者列表,我希望我包含了所有需要帮助我的文件
路线:
ZOZ::Application.routes.draw do
resources :refferals
#17 potwierdzanie rejestracji
resources :appointments do
collection do
get 'search'
get 'search_result'
get 'to_confirm'
end
member do
put :confirm
end
end
resources :clinics
resources :doctors
resources :patients do
collection do
get 'select51'
get 'index51'
end
member do
get 'show51'
end
end
get "welcome/index2"
get "welcome/index"
get 'appointments/create'
get 'appointments/move' => 'appointments#move'
post 'appointments/move' => 'appointments#doctors_list'
get 'appointments/move/:id' => 'appointments#doctor_appointments', as: :doctor_appointments
get 'appointments/change_appointment/:id' => 'appointments#change_appointment', as: :change_appointment
get 'appointments/change_doctor_and_appointment/:id' => 'appointments#change_doctor_and_appointment', as: :change_doctor_and_appointment
get 'appointments/success' => 'appointments#success'
# The priority is based upon order of creation:
# first created -> highest priority.
# Sample of regular route:
# match 'products/:id' => 'catalog#view'
# Keep in mind you can assign values other than :controller and :action
# Sample of named route:
# match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
# This route can be invoked with purchase_url(:id => product.id)
# Sample resource route (maps HTTP verbs to controller actions automatically):
# Sample resource route with options:
# resources :products do
# member do
# get 'short'
# post 'toggle'
# end
#
# collection do
# get 'sold'
# end
# end
# Sample resource route with sub-resources:
# resources :products do
# resources :comments, :sales
# resource :seller
# end
# Sample resource route with more complex sub-resources
# resources :products do
# resources :comments
# resources :sales do
# get 'recent', :on => :collection
# end
# end
# Sample resource route within a namespace:
# namespace :admin do
# # Directs /admin/products/* to Admin::ProductsController
# # (app/controllers/admin/products_controller.rb)
# resources :products
# end
# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
root :to => 'welcome#index'
# See how all your routes lay out with "rake routes"
# This is a legacy wild controller route that's not recommended for RESTful applications.
# Note: This route will make all actions in every controller accessible via GET requests.
# match ':controller(/:action(/:id))(.:format)'
end
患者/ index51:
<!-- ####################################################################################################### -->
<div id="container">
<center>
<h1>Wyniki wyszukiwania:</h1>
<p>
Lista pacjentów spełniających podane kryteria w porządku alfabetycznym
</br>
Wybierz odpowiedniego pacjenta aby przejść do kolejnego etapu!
</p>
<table border="1">
<thead>
<tr>
<th>Imie</th>
<th>Nazwisko </th>
<th>Adres</th>
<th>Pesel</th>
<th>Telefon</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% @patients.each do |patient| %>
<tr>
<td><%= patient.imie %></td>
<td><%= patient.nazwisko %></td>
<td><%= patient.adres %></td>
<td><%= patient.pesel %></td>
<td><%= patient.telefon %></td>
<td><%= link_to 'Wybierz pacjenta', show51_patient_path %></td>
</tr>
<% end %>
</tbody>
</table>
</br>
<%= link_to 'Powrót do wyszukiwarki', select51_patients_path %>
</center>
</div>
患者/ show51:
<!-- ####################################################################################################### -->
<div id="container">
<center>
<h3>Dane wybranego pacjenta:</h3>
<p>
<strong>Imie:</strong>
<%= @patient.imie %>
</p>
<p>
<strong>Nazwisko:</strong>
<%= @patient.nazwisko %>
</p>
<p>
<strong>Adres pacjenta:</strong>
<%= @patient.adres %>
</p>
<p>
<strong>Pesel pacjenta:</strong>
<%= @patient.pesel %>
</p>
<p>
<strong>Numer telefonu:</strong>
<%= @patient.telefon %>
</p>
<h3>Wybierz typ rejestracji aby przejść dalej:</h3>
<h4>
<%= link_to 'Rejestracja na wizytę', doctors_path %>
</br>
<%= link_to 'Rejestracja na badanie', clinics_path %>
</h4>
</br>
<%= link_to 'Powrót do wyszukiwarki', select51_patient_path %>
</center>
</div>
患者/ select51:
<!-- ####################################################################################################### -->
<div id="container">
<center>
<h1>Witaj!</h1>
<p>
Tutaj możesz zarejestrować pacjenta na:
</br>
1. wizytę do wybranego lekarza
</br>
2. konkretny typ badania
<h4>Wyszukaj pacjenta po numerze PESEL:</h4>
<%= form_tag(index51_patients_path, :method => "get", id: "search-form") do %>
<%= text_field_tag :search, params[:search], placeholder: "Tutaj wpisz dane" %>
<%= submit_tag "Przeszukaj bazę", :name => nil %>
<% end %>
<h5>
Uwaga! Możesz wyszukać również po nazwisku pacjenta!
</br>
Wystarczy wpisać je w powyższe pole zamiast numeru PESEL
</br>
Aby wyświetlić wszystkich pacjentów pozostaw pole puste!
</h5>
</p>
</center>
</div>
控制器:
class PatientsController < ApplicationController
# GET /patients
# GET /patients.json
def index51
@patients = Patient.all
if params[:search]
@patients = Patient.search(params[:search]).order("created_at ASC")
else
@patients = Patient.all.order('created_at ASC')
end
end
# GET /patients/select51
def select51
@patients = Patient.all
respond_to do |format|
format.html # select51.html.erb
format.json { render json: @patients }
end
end
# GET /patients/1
# GET /patients/1.json
def show51
@patient = Patient.find(params[:id])
session[:current_patient_id] = @patient.id
respond_to do |format|
format.html # show51.html.erb
format.json { render json: @patient }
end
end
# GET /patients/new
# GET /patients/new.json
def new
@patient = Patient.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @patient }
end
end
# GET /patients/1/edit
def edit
@patient = Patient.find(params[:id])
end
# POST /patients
# POST /patients.json
def create
@patient = Patient.new(params[:patient])
respond_to do |format|
if @patient.save
format.html { redirect_to @patient, notice: 'Patient was successfully created.' }
format.json { render json: @patient, status: :created, location: @patient }
else
format.html { render action: "new" }
format.json { render json: @patient.errors, status: :unprocessable_entity }
end
end
end
# PUT /patients/1
# PUT /patients/1.json
def update
@patient = Patient.find(params[:id])
respond_to do |format|
if @patient.update_attributes(params[:patient])
format.html { redirect_to @patient, notice: 'Patient was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @patient.errors, status: :unprocessable_entity }
end
end
end
# DELETE /patients/1
# DELETE /patients/1.json
def destroy
@patient = Patient.find(params[:id])
@patient.destroy
respond_to do |format|
format.html { redirect_to patients_url }
format.json { head :no_content }
end
end
end
错误:
NameError in Patients#index51
Showing D:/p15/app/views/patients/index51.html.erb where line #30 raised:
undefined local variable or method `show51_patients_path' for #<#<Class:0x70fbe10>:0x43b64e0>
Extracted source (around line #30):
27: <td><%= patient.adres %></td>
28: <td><%= patient.pesel %></td>
29: <td><%= patient.telefon %></td>
30: <td><%= link_to 'Wybierz pacjenta', show51_patients_path %></td>
31: </tr>
32: <% end %>
33: </tbody>
答案 0 :(得分:4)
<td><%= link_to 'Wybierz pacjenta', show51_patient_path %></td>
应该是
<td><%= link_to 'Wybierz pacjenta', show51_patient_path(patient) %></td>