Hi Folks, Just a quick question here. I have quite a large booking form that needs to be split into multiple pages, and am wondering how to approach this? Ideally I would like to validate the data at each stage, but only update the database after the final page is completed. I have Beta 3 of the Rails book (although I find reading PDFs for more than a few pages rather harder than reading a book) but can''t seem to find anything that explains how to do this (based on searches for "multiple pages" etc). If someone could point me in the direction of something (either online or in the Rails book) that explains how to do this, I would be most grateful. Cheers, ~Dave -- Dave Silvester Rent-A-Monkey Website Development Web: http://www.rentamonkey.com/
On 6/29/05, Dave Silvester <dave-AJqNGCqIqVQ7cdpDWioORw@public.gmane.org> wrote:> Hi Folks, > > Just a quick question here. I have quite a large booking form that needs to > be split into multiple pages, and am wondering how to approach this? Ideally > I would like to validate the data at each stage, but only update the database > after the final page is completed. > > I have Beta 3 of the Rails book (although I find reading PDFs for more than a > few pages rather harder than reading a book) but can''t seem to find anything > that explains how to do this (based on searches for "multiple pages" etc). > > If someone could point me in the direction of something (either online or in > the Rails book) that explains how to do this, I would be most grateful.Never tried this before, but you might be able to call the validation methods manually, and pass the information to the next form using the flash or session. Matt
Belorion wrote:> Never tried this before, but you might be able to call the validation > methods manually, and pass the information to the next form using the > flash or session.Ahh OK, so there isn''t really an "official" way to do it? I had already considered using hidden fields etc. as I would previously have done in PHP, so I guess I''ll just use the flash to place them in the next page of the form. Cheers, ~Dave -- Dave Silvester Rent-A-Monkey Website Development Web: http://www.rentamonkey.com/
On 6/29/05, Dave Silvester <dave-AJqNGCqIqVQ7cdpDWioORw@public.gmane.org> wrote:> Ahh OK, so there isn''t really an "official" way to do it? I had already > considered using hidden fields etc. as I would previously have done in PHP, so > I guess I''ll just use the flash to place them in the next page of the form.I would hardly take my suggestion as final :P... I''m not exactly a rails expert. But, to the best of my knowledge, since web apps are "stateless", the only way I know of to mimic state would be 1) Use the DB. This would not work for your situation, because you have an incomplete object. 2) Use the flash to communicate between actions/pages 3) Use session to communicate between actions/pages 4) Use hidden fields, ala your PHP app (which would be a less elegant way of doing #2)
Belorion wrote:> 1) Use the DB. This would not work for your situation, because you > have an incomplete object.I was considering that I could update the object and then have a "completed" field, but I''m trying to avoid having lots of incomplete db records from people just getting a quote etc. but not completing the booking.> 2) Use the flash to communicate between actions/pages > 3) Use session to communicate between actions/pages > 4) Use hidden fields, ala your PHP app (which would be a less elegant > way of doing #2)Ahh... see, you can probably tell I''m newer than you! I was thinking use the flash to put the hidden fields there, but I don''t need to do that because somehow the flash would communicate the current state to the next page? Perhaps someone could explain if that''s correct, or even how it works? Thanks for your help!! ~Dave -- Dave Silvester Music Technology Junkie | Rentable Website Monkey http://www.mu-sly.co.uk | http://www.rentamonkey.com
> Ahh... see, you can probably tell I''m newer than you! I was thinking use the > flash to put the hidden fields there, but I don''t need to do that because > somehow the flash would communicate the current state to the next page? > Perhaps someone could explain if that''s correct, or even how it works?Actually, I''ve never really used flash, so you''ll need someone to clarify that point for you ;)
Dave Silvester <dave-AJqNGCqIqVQ7cdpDWioORw@public.gmane.org> writes:> Just a quick question here. I have quite a large booking form that needs to > be split into multiple pages, and am wondering how to approach this? Ideally > I would like to validate the data at each stage, but only update the database > after the final page is completed.Seems like there was a solution for this in maybe edge rails; maybe it will make it to the pending 0.13 release. Anyway, it''s a conditional on the validation. I don''t remember exactly how it works. I participated in the thread. You might be able to find it in the gmane.org archive. Maybe someone will pipe up here. -- doug-jGAhs73c5XxeoWH0uzbU5w@public.gmane.org
Hello everybody ! Please let me introduce myself since it''s my first time here. I''m writing from Italy and I just started to play with Rails. I''m also an absolute beginner with Ruby though I''m not new to computer programming (though probably what I did in the last years would terrorize the youngest among you :-) Please consider the following: Class DutiesController < ApplicationController ... def list if @params[:date] == nil @filterDate = Date.today else @filterDate = params[:date] end @prvDate = @filterDate - 1 @duties = Duty.find(:all, :conditions => [ "date = ?", @filterDate]) ... end list.rhtml <h1>Listing duties for date <%= @filterDate.to_s %></h1> ... <%= link_to ''Previous date'', :action => ''list'', :date => @prvDate %> <%= link_to ''Next date'', :action => ''list'', :date => @filterDate.next %> No problem at the first run (http://localhost:3000/duties/list) but when I click on next or previous I get the message undefined method `-'' for "2005-06-30":String Please note that the find method works fine with a received date if I remove the line @prvDate = @filterDate - 1. Second problem: when I reach the end of the month @filterDate.next gives me 2005-06-31, 32, 33 and so on ! Many thanks in advance. Bruno
On Jun 29, 2005, at 8:24 AM, Doug Alcorn wrote:> Seems like there was a solution for this in maybe edge rails; maybe it > will make it to the pending 0.13 release. > > Anyway, it''s a conditional on the validation. I don''t remember > exactly how it works. I participated in the thread. You might be > able to find it in the gmane.org archive. Maybe someone will pipe up > here.The conditional validations in the soon-to-be 0.13 release would look like this: class MyModel < ActiveRecord::Base # Assuming completed_signup_step is a database field def past_step_one completed_signup_step > 1 end def past_step_two completed_signup_step > 2 end validates_presence_of :email validates_presence_of :address, :if => :past_step_one validates_presence_of :credit_card, :if => :past_step_two end Duane Johnson (canadaduane)
On 6/29/05, Bruno Bazzani <bruno.bazzani-nc/lrvXPQ4s@public.gmane.org> wrote:> Hello everybody ! > > Please let me introduce myself since it''s my first time here. > I''m writing from Italy and I just started to play with Rails. I''m also an > absolute beginner with Ruby though I''m not new to computer programming > (though probably what I did in the last years would terrorize the youngest > among you :-)Welcome aboard!> Please consider the following: > > Class DutiesController < ApplicationController > ... > def list > if @params[:date] == nil > @filterDate = Date.today > else > @filterDate = params[:date] > end > @prvDate = @filterDate - 1 > @duties = Duty.find(:all, :conditions => [ "date = ?", @filterDate]) > ... > end > > list.rhtml > <h1>Listing duties for date <%= @filterDate.to_s %></h1> > ... > <%= link_to ''Previous date'', :action => ''list'', :date => @prvDate %> > <%= link_to ''Next date'', :action => ''list'', :date => @filterDate.next %> > > No problem at the first run (http://localhost:3000/duties/list) > but when I click on next or previous I get the message > undefined method `-'' for "2005-06-30":String > > Please note that the find method works fine with a received date if I remove > the line @prvDate = @filterDate - 1.First off, I think you probably meant @filterDate = @params[:date] instead of @filterDate = params[:date] (though I thought I heard someone mention once either will work, but in either case you should probably be consistent) Secondly, it should be noted that anything contained by @params is going to be a string. @params is essentially what the browser is sending via a post or get request to the web server, and as such they must be simple. After all, the web browser has no concept of a Ruby object called Date. So, Date.today is giving you a Ruby Date object, while @params[:date] is giving you a string. So, you will need to convert that string into a date object before you can perform the - operation. That being said, I know rails has extended the Time/Date funcationality of Ruby, so their is likely an easier way to do this (someone please speak up!), but you could do Time.gm( *@params[:date].split("-") ) What I am doing is using the built in Time class in Ruby. Time.gm takes a list of specifications, as per http://www.rubycentral.com/ref/ref_c_time.html#gm. What the * before @params means is that I am taking the resulting array from split() and flattening it out. Hope that helps.
Duane Johnson <duane.johnson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:> The conditional validations in the soon-to-be 0.13 release would look > like this: > > class MyModel < ActiveRecord::Base > # Assuming completed_signup_step is a database field > > def past_step_one > completed_signup_step > 1 > end > > def past_step_two > completed_signup_step > 2 > end > > validates_presence_of :email > validates_presence_of :address, :if => :past_step_one > validates_presence_of :credit_card, :if => :past_step_two > endThis makes me smile! Thanks Duane. -- doug-jGAhs73c5XxeoWH0uzbU5w@public.gmane.org
Doug Alcorn wrote:> This makes me smile! Thanks Duane.Indeed, this is cool, thanks Duane. Can we use this just by installing edge rails as per... http://wiki.rubyonrails.com/rails/show/EdgeRails ...? Or if 0.13 isn''t that far away, I might just wait and work on another bit of my app for now. Actually, considering I''m already using beta rails, perhaps I should just try and see if it''s already working? Hmmmm.... ~Dave -- Dave Silvester Rent-A-Monkey Website Development Web: http://www.rentamonkey.com/
On Jun 29, 2005, at 9:49 AM, Belorion wrote:> Time.gm( *@params[:date].split("-") ) >date = Date.parse(@params[:date]) should do it. Duane Johnson (canadaduane) _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On Jun 29, 2005, at 10:33 AM, Dave Silvester wrote:> Indeed, this is cool, thanks Duane. Can we use this just by > installing edge rails as per... > > http://wiki.rubyonrails.com/rails/show/EdgeRails > > ...? Or if 0.13 isn''t that far away, I might just wait and work on > another bit of my app for now. > > Actually, considering I''m already using beta rails, perhaps I > should just try and see if it''s already working? Hmmmm....I''m pretty sure it''s in beta rails already. It''s definitely in edge rails. Duane Johnson (canadaduane) _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On Wednesday 29 June 2005 14:49, Dave Silvester wrote:> Just a quick question here. I have quite a large booking form that > needs to be split into multiple pages, and am wondering how to > approach this? Ideally I would like to validate the data at each > stage, but only update the database after the final page is > completed.Do you have to spread the form across multiple pages because the later pages differ depending on the former pages or is it just a matter of layout? If the latter, you may consider to load the entire form in one document, but only show parts of it with (in-page) tabs. This has the additional benefit for the user that switching among the parts of the form is very fast. Michael -- Michael Schuerig There is no matrix, mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org only reality. http://www.schuerig.de/michael/ --Lawrence Fishburn
Michael Schuerig wrote:> Do you have to spread the form across multiple pages because the later > pages differ depending on the former pages or is it just a matter of > layout?As it''s a booking system, later parts of the form differ depending on the requirements of the person making the booking. They get a quote, then approve it and make the final booking and so on.> If the latter, you may consider to load the entire form in one document, > but only show parts of it with (in-page) tabs. This has the additional > benefit for the user that switching among the parts of the form is very > fast.Come to think of it, it might actually be quite easy (and cool, not to mention blowing the client away with the slick user experience) to use AJAX to get the quote and so on without having to submit the form... hmm... I''m gonna have a think about this. I think it''s probably still necessary to get the quote on the first page before people start entering their details for the booking. At the moment, I''m only supposed to be building a prototype version anyway, so perhaps I''ll just show them and see what they think. (Obviously will have to include regular form handling for those without JavaScript.) I haven''t used the Rails AJAX stuff yet, but I''m sure it''s fun! :-D ~Dave -- Dave Silvester Rent-A-Monkey Website Development Web: http://www.rentamonkey.com/
On 29/06/2005, at 10:49 PM, Dave Silvester wrote:> Hi Folks, > > Just a quick question here. I have quite a large booking form that > needs to be split into multiple pages, and am wondering how to > approach this? Ideally I would like to validate the data at each > stage, but only update the database after the final page is completed.Chances are you''ll end up actually wanting to store the partial object in the database for metrics etc. Anyways, here''s a solution we used a while ago: http://www.bigbold.com/snippets/posts/show/277 The multi-step is done at the controller level, with the model unaware of multistep and not having to change any validation rules. The code could be cleaned up a little, but well worked for us at the time. If you''ve got complex (custom) validation it may not be enough, but for most cases it should be fine... - tim lucas