I want to create a route for any image. This is in order to create an email report explaining what the missing image is. I could create a route for each directory that currently has images in it but wanted something more general like: map.connect "/**/*.gif", :controller => ''image_handler'', :action => ''handle_image'' Which doesn''t work. Anyone know more about the inner workings? Dave -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060315/44ba1c66/attachment.html
You can only use * once. It catches everything and stores it into a variable of your choosing. (e.g. map.connect ''*path'' will give you the contents of the URL in params[:path]) So... map.connect ''some/*path'', :controller => ''pages'', :action => ''bad_request'' But... I don''t think routes are the best way to achieve your goal, if your goal is to scan your site for broken images. (What WOULD be a good way I dunno...) (I doubt you can even do what you want with routes...) - Rabbit --- On 3/15/06, David Clements <digidigo@gmail.com> wrote:> I want to create a route for any image. This is in order to create an email > report explaining what the missing image is. I could create a route for > each directory that currently has images in it but wanted something more > general like: > > > map.connect "/**/*.gif", :controller => ''image_handler'', :action => > ''handle_image'' > > > Which doesn''t work. Anyone know more about the inner workings? > > Dave > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >
Here''s one way: In your config/routes.rb file: map.connect "*anything", :controller => "unknown", :action => "unknown_url" In your app/controllers/unknown_controller.rb file: # Unknown URLs get routed to this action. def unknown_url missing_image = @request.request_uri.match(/.*\/(.*.(gif|jpg|jpeg|png))/i) if missing_image img_name = missing_image[1] logger.error("Request for nonexistent image #{img_name} at URI #{@request.request_uri}...") # Send your email here... end ... end -Doug On 3/15/06, David Clements <digidigo@gmail.com> wrote:> I want to create a route for any image. This is in order to create an email > report explaining what the missing image is. I could create a route for > each directory that currently has images in it but wanted something more > general like: > > > map.connect "/**/*.gif", :controller => ''image_handler'', :action => > ''handle_image'' > > > Which doesn''t work. Anyone know more about the inner workings? > > Dave > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >