Sunday, 15 January 2012

Ruby Adding to DB not working -



Ruby Adding to DB not working -

i have problem because date_time doeasn't go database help me ? go new51 form51 , utilize create51 method. still app creates empty date_time filed in db. why?

apppointment_controller:

class appointmentscontroller < applicationcontroller before_filter :load_appointment, only: [:show, :update, :edit, :destroy] before_filter :load_wizard, only: [:new, :edit, :create] def searchd end def move end def doctors_list @doctors = doctor.where("imie_lekarza ? or nazwisko_lekarza ? or specjalizacja ?", "%#{params[:search]}%", "%#{params[:search]}%", "%#{params[:search]}%") end def doctor_appointments @doctor = doctor.find(params[:id]) @appointments = @doctor.appointments end def change_appointment @appointment = appointment.find(params[:id]) end def change_doctor_and_appointment @doctors = doctor.all @appointment = appointment.find(params[:id]) end def success @notice = flash[:notice] end def searchdate d = params[:date] info = date.new(d["(1i)"].to_i, d["(2i)"].to_i, d["(3i)"].to_i) @appointments = appointment.scoped @appointments = @appointments.where(:data_godzina_wizyty => data.beginning_of_day..data.end_of_day) end def search_not end def search_result_not #pacjent @patients = patient.scoped @patients = @patients.where(pesel: params[:pesel]) d = params[:date] if d["(1i)"] != "" , d["(2i)"]. != "" , d["(3i)"] != "" info = date.new(d["(1i)"].to_i, d["(2i)"].to_i, d["(3i)"].to_i) @appointments = @patients.first.appointments.where(:data_godzina_wizyty => data.beginning_of_day..data.end_of_day) else @appointments = @patients.first.appointments end end def add_or_edit_not session['last_search_not'] = 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 update_not @appointment = appointment.find(params[:id]) @appointment.notatka = params[:notatka] if @appointment.save redirect_to session[:last_search_not], notice: 'notatka zostala zapisana.' else redirect_to :back, notice: 'niestety wystapil blad. prosze sprubowac pozniej' end end def search end def new51 @appointment = appointment.new respond_to |format| format.html # new51.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: 'wizyta zostala pomyslnie utworzona.' } format.json { render json: @appointment, status: :created, location: @appointment } else format.html { render action: "new51" } 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 @appointment = appointment.find(params[:id]) @old_appointment = @appointment.dup respond_to |format| if @appointment.update_attributes(params[:appointment]) defaultmailer.move_appointment(@appointment, @old_appointment).deliver format.html { redirect_to appointments_success_path, notice: 'pomyslnie zmieniono termin.' } format.json { head :no_content } else format.html { render action: "edit" } format.json { render json: @appointment.errors, status: :unprocessable_entity } end 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.html.erb:

<%= form_for @appointment, :url => url_for(:action => "create51") |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 %>

new51.html.erb:

<div id="container"> <center> <h1>nowa wizyta:</h1> <p>sprawdz poprawnosc ponizszych danych nastepnie uzupelnij formularz.</p> <h3>dane lekarza:</h3> <p> <strong>imiÄ™ lekarza:</strong> <%= doctor.find(session[:current_doctor_id2]).imie_lekarza %> </p> <p> <strong>nazwisko lekarza:</strong> <%= doctor.find(session[:current_doctor_id2]).nazwisko_lekarza %> </p> <p> <strong>specjalizacja lekarza:</strong> <%= doctor.find(session[:current_doctor_id2]).specjalizacja %> </p> <h3>dane pacjenta:</h3> <p> <strong>imie:</strong> <%= patient.find(session[:current_patient_id]).imie %> </p> <p> <strong>nazwisko:</strong> <%= patient.find(session[:current_patient_id]).nazwisko %> </p> <p> <strong>pesel:</strong> <%= patient.find(session[:current_patient_id]).pesel %> </p> <%= render "form51", locals: { appointment: @appointment } %> <%= link_to 'wybierz innego lekarza', index51_doctors_path %> </br> </center> </div>

according comments above problem have used

@appointment = appointment.new(params[:patient])

you initialising appointment with params[:patient] params coming form more "appointment"=>{} instead should

@appointment = appointment.new(params[:appointment])

this initialise appointment params coming form.

ruby-on-rails ruby

No comments:

Post a Comment