--sending again, didn''t see it on mailing list Hey all, I''ve been checking out ruby and rails for a couple weeks now, and did both the onLamp and 4 days on rails tutorials. So far the ride has been great. I''ve asked this question in #rubyonrails before, but never got a real answer: In both tutorials (onLamp and 4DaysOnRails), there seems to be 2 ways of validating data and then informing the user. The first way is through the model, using the various validate_ methods. The second way is through the controller, using flash[''notice''] to inform the user of a changed status (new record, edited record, etc). The question I have is when you want to validate form fields that are not directly related to the model. Or just pretend that your web application does not use a database. In this instance, how do you validate form data, such as required fields, minimum max lengths, etc? How do you correspondingly inform the user of errors while validating? Some suggestions I got were: use flash[''notice''] append to errors object <- does this exist? is this possible? build my own =) Any responses greatly appreciated. Thank you everyone, Jin Lee
im new to rails (who isnt), and am about to dive in with a podcasting project. i see the stuff on generating xml (http://wiki.rubyonrails.com/rails/show/HowtoGenerateXml), but has anyone implemented this with an RSS enclosure? obviously you could hard code it, but i''d like the client to upload an mp3 file as an attachment to a blog entry, record that uploaded filename, and have rails automatically add the enclosure to the rss feed based on the presence of that related file. any links or ideas would be appreciated and cited. thanks!
You can put anything in flash that you''d like and it will stay around for the next request. I would just put it in the controller code for the form submit action and append to a list of errors. Then in your view, iterate over the list and print them out however you like. Alternately, make a hash of errors, keyed by form field name or something else so you can put the messages in specific spots. Even better, write helper methods to make this process more generic. If you''re doing this sort of validation all over the place, then you''ll want it to be easy to use. If you''re using redirects, you can stick your errors object (hash, list, otherwise) into flash. Honestly, rolling your own, for most simple cases, could be 10-20 lines of code and give you a nice general helper module. It''s probably worth doing. Ruby is great at this sort of thing. Good luck, Brian On 4/23/05, Jin Lee <jinslee-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> --sending again, didn''t see it on mailing list > > Hey all, > > I''ve been checking out ruby and rails for a couple weeks now, and did > both the onLamp and 4 days on rails tutorials. So far the ride has > been great. > > I''ve asked this question in #rubyonrails before, but never got a real answer: > > In both tutorials (onLamp and 4DaysOnRails), there seems to be 2 ways > of validating data and then informing the user. The first way is > through the model, using the various validate_ methods. The second way > is through the controller, using flash[''notice''] to inform the user of > a changed status (new record, edited record, etc). > > The question I have is when you want to validate form fields that are > not directly related to the model. Or just pretend that your web > application does not use a database. In this instance, how do you > validate form data, such as required fields, minimum max lengths, etc? > How do you correspondingly inform the user of errors while validating? > > Some suggestions I got were: > use flash[''notice''] > append to errors object <- does this exist? is this possible? > build my own =) > > Any responses greatly appreciated. Thank you everyone, > > Jin Lee > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- The years ahead pick up their dark bags. They move closer. There''s a slight rise in the silence then nothing. -- (If you''re receiving this in response to mail sent to bluczkie-OM76b2Iv3yLQjUSlxSEPGw@public.gmane.org, don''t be concerned This is my new address, but mail will be forwarded here indefinitely)
Hi Jin, I think you shouldn''t abandon the rails validation methods, but use them as a starting point. This is what I do. 1. I perform the rails validation 2. Copy those to my own errors hash 3. perform my own error checks 4. Maybe remove any errors that rails added that aren''t needed in this context. Here is some code snippets: @myerrors = Hash.new @holder = Holder.find_first(["login_id=?",@session[''login''][''id'']]) if not @holder.valid?() then #copy errors to my own hash (Humanize makes the field name nicer) @holder.errors.each {|key,value| @myerrors[key]=key.humanize + '' '' + value} end #add my own validation if @holder.os == ''windows'' then @myerrors = {"os" => "David won''t let you work here, so don''t bother applying"} End if @myerrors.empty? #save my record else #render view showing myerror hash End Joe -----Original Message----- From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Jin Lee Sent: Friday, April 22, 2005 10:03 PM To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: [Rails] newbie question regarding validation --sending again, didn''t see it on mailing list Hey all, I''ve been checking out ruby and rails for a couple weeks now, and did both the onLamp and 4 days on rails tutorials. So far the ride has been great. I''ve asked this question in #rubyonrails before, but never got a real answer: In both tutorials (onLamp and 4DaysOnRails), there seems to be 2 ways of validating data and then informing the user. The first way is through the model, using the various validate_ methods. The second way is through the controller, using flash[''notice''] to inform the user of a changed status (new record, edited record, etc). The question I have is when you want to validate form fields that are not directly related to the model. Or just pretend that your web application does not use a database. In this instance, how do you validate form data, such as required fields, minimum max lengths, etc? How do you correspondingly inform the user of errors while validating? Some suggestions I got were: use flash[''notice''] append to errors object <- does this exist? is this possible? build my own =) Any responses greatly appreciated. Thank you everyone, Jin Lee _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
We do enclosures with the xml builder for odeo.... In general we''ve not been to happy with xml builder''s performance, but it works. Here''s an example: for q in @queued_audios xml.item do xml.title( q.audio.title ) xml.enclosure( "url"=> q.audio.external_url, "length"=> q.audio.size_in_bytes, "type"=>"audio/mpeg") xml.guid("tag:odeo.com,#{q.audio.created_at},#{q.audio.id}") end end On 4/22/05, jason lynes :: senyl.com <jason-9ZYj/DJVokUAvxtiuMwx3w@public.gmane.org> wrote:> im new to rails (who isnt), and am about to dive in with a podcasting > project. i see the stuff on generating xml > (http://wiki.rubyonrails.com/rails/show/HowtoGenerateXml), but has > anyone implemented this with an RSS enclosure? obviously you could hard > code it, but i''d like the client to upload an mp3 file as an attachment > to a blog entry, record that uploaded filename, and have rails > automatically add the enclosure to the rss feed based on the presence of > that related file. > > any links or ideas would be appreciated and cited. thanks! > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
caches_page is way to go on all xml exports. On 4/25/05, evan <anarchogeek-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> We do enclosures with the xml builder for odeo.... In general we''ve > not been to happy with xml builder''s performance, but it works. > > Here''s an example: > > for q in @queued_audios > xml.item do > xml.title( q.audio.title ) > xml.enclosure( "url"=> q.audio.external_url, "length"=> > q.audio.size_in_bytes, "type"=>"audio/mpeg") > xml.guid("tag:odeo.com,#{q.audio.created_at},#{q.audio.id}") > end > end > > > On 4/22/05, jason lynes :: senyl.com <jason-9ZYj/DJVokUAvxtiuMwx3w@public.gmane.org> wrote: > > im new to rails (who isnt), and am about to dive in with a podcasting > > project. i see the stuff on generating xml > > (http://wiki.rubyonrails.com/rails/show/HowtoGenerateXml), but has > > anyone implemented this with an RSS enclosure? obviously you could hard > > code it, but i''d like the client to upload an mp3 file as an attachment > > to a blog entry, record that uploaded filename, and have rails > > automatically add the enclosure to the rss feed based on the presence of > > that related file. > > > > any links or ideas would be appreciated and cited. thanks! > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Tobi http://www.snowdevil.ca - Snowboards that don''t suck http://www.hieraki.org - Open source book authoring http://blog.leetsoft.com - Technical weblog
Jason - I also just found this - http://podcast.rubyforge.org - while surfing rubyforge. Might be what you''re looking for. Jesse On 4/26/05, Tobias Luetke <tobias.luetke-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> caches_page is way to go on all xml exports. > > On 4/25/05, evan <anarchogeek-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > We do enclosures with the xml builder for odeo.... In general we''ve > > not been to happy with xml builder''s performance, but it works. > > > > Here''s an example: > > > > for q in @queued_audios > > xml.item do > > xml.title( q.audio.title ) > > xml.enclosure( "url"=> q.audio.external_url, "length"=> > > q.audio.size_in_bytes, "type"=>"audio/mpeg") > > xml.guid("tag:odeo.com,#{q.audio.created_at},#{q.audio.id}") > > end > > end > > > > > > On 4/22/05, jason lynes :: senyl.com <jason-9ZYj/DJVokUAvxtiuMwx3w@public.gmane.org> wrote: > > > im new to rails (who isnt), and am about to dive in with a podcasting > > > project. i see the stuff on generating xml > > > (http://wiki.rubyonrails.com/rails/show/HowtoGenerateXml), but has > > > anyone implemented this with an RSS enclosure? obviously you could hard > > > code it, but i''d like the client to upload an mp3 file as an attachment > > > to a blog entry, record that uploaded filename, and have rails > > > automatically add the enclosure to the rss feed based on the presence of > > > that related file. > > > > > > any links or ideas would be appreciated and cited. thanks! > > > _______________________________________________ > > > Rails mailing list > > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > -- > Tobi > http://www.snowdevil.ca - Snowboards that don''t suck > http://www.hieraki.org - Open source book authoring > http://blog.leetsoft.com - Technical weblog > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- jnewland-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org jnewland.com 706.340.3625