Ruby error with form -
how create route appointment/new51 action create51 action ? because automatically redirect me create , don't want this. new in ruby , have lots of problems school project finished:) routes.rb:
zoz::application.routes.draw resources :refferals collection 'new51' end fellow member 'show' end end #17 potwierdzanie rejestracji resources :appointments collection 'search' 'search_result' 'to_confirm' 'new51' end fellow member set :confirm set :create51 end end resources :clinics collection 'index51' end fellow member 'show51s' end end resources :doctors collection 'index51a' 'index51' end fellow member 'show51s' 'show51ss' end end resources :patients collection 'select51' 'index51' end fellow member 'show51s' 'show51ss' end end "welcome/index2" "welcome/index" 'appointments/create' 'appointments/move' => 'appointments#move' post 'appointments/move' => 'appointments#doctors_list' 'appointments/move/:id' => 'appointments#doctor_appointments', as: :doctor_appointments 'appointments/change_appointment/:id' => 'appointments#change_appointment', as: :change_appointment 'appointments/change_doctor_and_appointment/:id' => 'appointments#change_doctor_and_appointment', as: :change_doctor_and_appointment 'appointments/success' => 'appointments#success' # priority based upon order of creation: # first created -> highest priority. # sample of regular route: # match 'products/:id' => 'catalog#view' # maintain in mind can assign values other :controller , :action # sample of named route: # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase # route can invoked purchase_url(:id => product.id) # sample resource route (maps http verbs controller actions automatically): # sample resource route options: # resources :products # fellow member # 'short' # post 'toggle' # end # # collection # 'sold' # end # end # sample resource route sub-resources: # resources :products # resources :comments, :sales # resource :seller # end # sample resource route more complex sub-resources # resources :products # resources :comments # resources :sales # 'recent', :on => :collection # end # end # sample resource route within namespace: # namespace :admin # # directs /admin/products/* admin::productscontroller # # (app/controllers/admin/products_controller.rb) # resources :products # end # can have root of site routed "root" # remember delete public/index.html. root :to => 'welcome#index' # see how routes lay out "rake routes" # legacy wild controller route that's not recommended restful applications. # note: route create actions in every controller accessible via 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 |format| format.html # new.html.erb format.json { render json: @appointment } end end def create51 @appointment = appointment.new(params[:appointment]) respond_to |format| if @appointment.save format.html { redirect_to @appointment, notice: 'appointment created.' } format.json { render json: @appointment, status: :created, location: @appointment } else format.html @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] info = 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) homecoming 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 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) |f| %> <% if @appointment.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(@appointment.errors.count, "error") %> prohibited appointment beingness saved:</h2> <ul> <% @appointment.errors.full_messages.each |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 %> wymaga_potwierdzenia != wymaga_potwierdzenia
correct right method/column name.
ruby-on-rails ruby controller
No comments:
Post a Comment