On 30 June 2016 at 15:27, Ruth Stephenson <li...@ruby-forum.com> wrote: > Hi, I have a very beginners understanding of rails and ruby and I keep > getting stuck. Some previous posts have helped me a great deal but I now > have a different issue and so I thought I should start another post with > a different topic. > > 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 > && timeslot 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. I have created a method called isValid? in the model (See below)
You should probably be using rails validations for this, most of the work will then be done for you by rails. I suggest that you work right through a good tutorial such as railstutorial.org, which will show you the basics of rails and save both yourself and us a lot of time in the long run. To get a flavour of validations you can look at the Rails Guide on ActiveRecord Validations. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLtfKWkRSDnZzu7H83RZusKv69aKJnf_qoCE9UdOPp7JWg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.