Greetings! I''m having a hard time understanding the way Rails handles urls. I''m specifically having real trouble with the image_urls in the Depot app in the Agile Web Development book. If I enter "\image\file.png" in the Add Product page, the image is displayed in the other views and Properties shows http://localhost:3000/images/file.png If I leave off the leading backslash and enter "image\file.png" the image does not display and Properties shows http://localhost:3000/admin/images/file.png when I look at it from the admin_controller or http://localhost:3000/store/images/file.png when I look at it from the store_controller. In either case, the validation the book shows for image_url really trips me up because it''s checking to see that the string begins with "http:". What''s up with that? Also, when I''m supplying the location in the unit test I''m having to use a string I really don''t understand. The string is: "c:\\instantrails\rails_apps\\depot\\public\\images\rails.png" Why do some of the ''\'' characters have to be escaped and others not? Or is that not what''s going on? Could someone help? At least point me to some docs on this topic? Thanks, Bill -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060219/8f7390a1/attachment.html
Bill Walton wrote:> > In either case, the validation the book shows for image_url really trips > me up because it''s checking to see that the string begins with "http:". > What''s up with that?This was a mistake the made and they have updated the PDF that now have the following validation code: validates_format_of :image_url, :with => %r{\.(gif|jpg|png)$}i, :message => "must be a URL for a GIF, JPG, or PNG image" Here is an entry in the errata at the Pragmatic website: "At bottom of page 69 yous suggest to add some image ... well it''s nice BUT .... since at botom of page 66 page you make us write a validates rule where image_url must begin with http: i don''t realy know what to append in the input field image_url to point out the right image ... is that http://localhost:3000/public/images/toto.png or whatever ? you should there help us in the deep with an example i suggest ... (sorry but i''m not a good english speaker ... d?ja en francais j''ai du mal alors ....) (not good english speaker ... sorry) (Dave says: I''ve finally given in on this and removed the check for the leading http)--ovnk" Hope this helps a bit /Stefan -- Posted via http://www.ruby-forum.com/.
Thanks for clearing up that part of my confusion, Stefan. I appreciate it. Best regards, Bill ----- Original Message ----- From: "Stefan Liden" <stefan.liden@gmail.com> To: <rails@lists.rubyonrails.org> Sent: Sunday, February 19, 2006 5:27 PM Subject: [Rails] Re: Rails urls & the AWD book> Bill Walton wrote: > > > > In either case, the validation the book shows for image_url really trips > > me up because it''s checking to see that the string begins with "http:". > > What''s up with that? > > This was a mistake the made and they have updated the PDF that now have > the following validation code: > > validates_format_of :image_url, > :with => %r{\.(gif|jpg|png)$}i, > :message => "must be a URL for a GIF, JPG, or PNG image" > > Here is an entry in the errata at the Pragmatic website: > "At bottom of page 69 yous suggest to add some image ... well it''s nice > BUT .... > since at botom of page 66 page you make us write a validates rule where > image_url must begin with http: i don''t realy know what to append in the > input field image_url to point out the right image ... is that > http://localhost:3000/public/images/toto.png or whatever ? > you should there help us in the deep with an example i suggest ... > (sorry but i''m not a good english speaker ... d?ja en francais j''ai du > mal alors ....) > (not good english speaker ... sorry) > > (Dave says: I''ve finally given in on this and removed the check for the > leading http)--ovnk" > > Hope this helps a bit > /Stefan > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Bill, I remember running into the same problem with the book. Here is an errata from the web site ... basically the validation is broken: #896: The suggested image url is relative /images/sk_auto_small.jpg but the validation requires a full url starting with http. (Dave says: I''m going to tidy all that up in the next edition: it was a change made at the suggestion of a reviewer, but in retrospect I regret it) http://books.pragprog.com/titles/rails/errata -Steve ________________________________ From: rails-bounces@lists.rubyonrails.org [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Bill Walton Sent: Sunday, February 19, 2006 2:44 PM To: rails@lists.rubyonrails.org Subject: [Rails] Rails urls & the AWD book Greetings! I''m having a hard time understanding the way Rails handles urls. I''m specifically having real trouble with the image_urls in the Depot app in the Agile Web Development book. If I enter "\image\file.png" in the Add Product page, the image is displayed in the other views and Properties shows http://localhost:3000/images/file.png If I leave off the leading backslash and enter "image\file.png" the image does not display and Properties shows http://localhost:3000/admin/images/file.png when I look at it from the admin_controller or http://localhost:3000/store/images/file.png when I look at it from the store_controller. In either case, the validation the book shows for image_url really trips me up because it''s checking to see that the string begins with "http:". What''s up with that? Also, when I''m supplying the location in the unit test I''m having to use a string I really don''t understand. The string is: "c:\\instantrails\rails_apps\\depot\\public\\images\rails.png" Why do some of the ''\'' characters have to be escaped and others not? Or is that not what''s going on? Could someone help? At least point me to some docs on this topic? Thanks, Bill -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060222/c0cf78a8/attachment.html