I'm sorry if this should be in the Ruby forum. I decided to put it here as i'm developing in rails but I'm new to both. I am also wondering if I'm putting the methods into the right files in rails, therefore I thought to post in the rails forum.
I am making an appointment booking app and I have a very basic design. I have created an appointments scaffold with name:string phone:string email:string numpeople:integer date:date timeslot:string. On the view for creating a new appointment I have stated that appointment 1 is 9-11am, appointment 2 is 12-2pm, appointment 3 is 3-5pm and appointment 4 is 5 - 7pm. The user is asked to enter 1,2,3 or 4.
When the user clicks on "make appointment" I'm trying to interrupt the appointments controller (create method) so that I can check if the date&×lot are nil. if that is the case, the system should continue on to create the appointment, if not then I want to redirect to somewhere else.
My code is not working and I'm very stuck (as I said I'm very new to
this) Am I going about this in the correct way? I am aware this is not
the best way to go about it, but this is the simplist way I know when I
am not familiar with the language and framework, so please humour my
roundabout methods
Please can anyone give me some pointers. (The entire appointments controller is mentioned at the bottom of this post, in case it is required)
def create # what I have for create so far @appointment = Appointment.new(appointment_params) @appointments.find(params[:date, :timeslot])
if @appointments.date.nil? and @appointments.timeslot.nil? respond_to do |format| if @appointment.save format.html { redirect_to @appointment, notice: 'Appointment was successfully created.' } format.json { render :show, status: :created, location: @appointment } elsif format.html { render :new } format.json { render json: @appointment.errors, status: :unprocessable_entity } end
redirect_to page_home_path end end end