如何从约会/ new51操作到create51操作的路由?因为它会自动重定向我创建,我不想这样做。我是Ruby的新手,我的学校项目有很多问题,但它几乎完成了:) routes.rb中:
ZOZ::Application.routes.draw do
resources :refferals do
collection do
get 'new51'
end
member do
get 'show'
end
end
#17 potwierdzanie rejestracji
resources :appointments do
collection do
get 'search'
get 'search_result'
get 'to_confirm'
get 'new51'
end
member do
put :confirm
put :create51
end
end
resources :clinics do
collection do
get 'index51'
end
member do
get 'show51s'
end
end
resources :doctors do
collection do
get 'index51a'
get 'index51'
end
member do
get 'show51s'
get 'show51ss'
end
end
resources :patients do
collection do
get 'select51'
get 'index51'
end
member do
get 'show51s'
get 'show51ss'
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
Appointments_controller:
class AppointmentsController < ApplicationController
before_filter :load_appointment, only: [:show, :update, :edit, :destroy]
before_filter :load_wizard, only: [:new, :edit, :create, :update]
def search
end
def new51
@doctors_workplace = DoctorsWorkplace.scoped
@doctors_workplace = @doctors_workplace.where(doctor_id: Doctor.find(session[:current_doctor_id2]).id)
@appointment = Appointment.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @appointment }
end
end
def create51
@appointment = Appointment.new(params[:appointment])
respond_to do |format|
if @appointment.save
format.html { redirect_to @appointment, notice: 'Appointment was successfully created.' }
format.json { render json: @appointment, status: :created, location: @appointment }
else
format.html do
@schedules = Schedule.scoped
@schedules = @schedules.where(doctor_id: Doctor.find(session[:current_doctor_id2]).id)
render action: "new51"
end
format.json { render json: @appointment.errors, status: :unprocessable_entity }
end
end
end
def search_result
d = params[:date]
data = Date.new(d["(1i)"].to_i, d["(2i)"].to_i, d["(3i)"].to_i)
#szukanie pacjenta
@patients = Patient.scoped
@patients = @patients.where(pesel: params[:pesel])
if params[:imie] != ""
@patients = @patients.where(imie: params[:imie])
end
if params[:nazwisko] != ""
@patients = @patients.where(nazwisko: params[:nazwisko])
end
#szukanie doctora
opcja = 0
@doctors = Doctor.scoped
if params[:imie_lekarza] != ""
@doctors = @doctors.where(imie_lekarza: params[:imie_lekarza])
opcja = 1
end
if params[:nazwisko_lekarza] != ""
@doctors = @doctors.where(nazwisko_lekarza: params[:nazwisko_lekarza])
opcja = 1
end
#zlaczenie
@patient_appo = @patients.first.appointments.where(:data_godzina_wizyty => data.beginning_of_day..data.end_of_day, potwierdzona: false)
if opcja == 1
@doctors_appo = @doctors.first.appointments.where(:data_godzina_wizyty => data.beginning_of_day..data.end_of_day, potwierdzona: false)
@appointments = @patient_appo & @doctors_appo
else
@appointments = @patient_appo
end
end
def to_confirm
session['last_search'] = request.env["HTTP_REFERER"]
@appointment = Appointment.find(params[:id])
@patient = Patient.find(@appointment.patient_id)
if @appointment.doctor_id != nil
@doctor = Doctor.find(@appointment.doctor_id)
end
if @appointment.refferal_id != nil
@refferal = Refferal.find(@appointment.refferal_id)
end
end
def confirm
@appointment = Appointment.find(params[:id])
@appointment.potwierdzona = true
if @appointment.save
#redirect_to :back, notice: 'Rejestracja zostala pomyslnie potwierdzona.'
redirect_to session[:last_search], notice: 'Rejestracja zostala pomyslnie potwierdzona.'
else
redirect_to :back, notice: 'Niestety wystapil blad. Prosze sprubowac pozniej'
end
end
def index
@appointments = Appointment.all
end
def show
end
def new
@appointment = @wizard.object
@clinics = Clinic.all
@doctors = Doctor.all
end
public
def findDoctorViaClinic( clinic )
return( (Clinic.find( clinic )).doctors.uniq )
end
helper_method :findDoctorViaClinic
def findScheduleViaDoctor(d)
s = Schedule.includes(:doctors_workplace).where(doctors_workplace_id: (DoctorsWorkplace.includes(:doctor).where(doctor_id: d)) ).where(taken: 0)
return s
end
helper_method :findScheduleViaDoctor
def edit
end
def create
@appointment = @wizard.object
if @wizard.save
s = ( Schedule.find( @appointment.schedule.id ) )
s.taken = true
s.save
redirect_to @appointment, notice: "Appointment saved!"
else
render :new
end
end
def update
if @wizard.save
redirect_to @appointment, notice: 'Appointment was successfully updated.'
else
render action: 'edit'
end
end
def destroy
@appointment.destroy
redirect_to appointments_url
end
private
def load_appointment
@appointment = Appointment.find(params[:id])
end
def load_wizard
@wizard = ModelWizard.new(@appointment || Appointment, session, params)
if self.action_name.in? %w[new edit]
@wizard.start
elsif self.action_name.in? %w[create update]
@wizard.process
end
end
end
_form51:
<%= form_for(@appointment) do |f| %>
<% if @appointment.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@appointment.errors.count, "error") %> prohibited this appointment from being saved:</h2>
<ul>
<% @appointment.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :data_godzina_wizyty %><br />
<%=
options = { start_year: 2.year.from_now.year,
end_year: 2013,
include_blank: true,
default: nil }
f.datetime_select :data_godzina_wizyty, options
%>
<!--<input type="text" data-behaviour='datepicker' :data_wizyty > -->
</div>
<div class="field">
<%= f.hidden_field :doctor_id, :value => Doctor.find(session[:current_doctor_id2]).id %>
</div>
<div class="field">
<%= f.hidden_field :patient_id, :value => Patient.find(session[:current_patient_id]).id %>
</div>
<div class="actions">
<%= submit_tag "Utworz wizyte" %>
</div>
<% end %>
答案 0 :(得分:1)
wymaga_Potwierdzenia != wymaga_potwierdzenia
更正正确的方法/列名称。