Let''s say for the sake of argument that I wanted to change this code in C:\ruby\lib\ruby\gems\1.8\gems\actionpack-1.10.1\lib\action_controller\u rl_rewriter.rb private def rewrite_url(path, options) rewritten_url = "" unless options[:only_path] rewritten_url << (options[:protocol] || @request.protocol) rewritten_url << (options[:host] || @request.host_with_port) end rewritten_url << @request.relative_url_root.to_s unless options[:skip_relative_url_root] rewritten_url << path rewritten_url << ''/'' if options[:trailing_slash] rewritten_url << "##{options[:anchor]}" if options[:anchor] rewritten_url end How would I do this in my application only? Would I just do class UrlRewriter private def rewrite_url(path, options) # my new logic here rewritten_url end End And then just require this somewhere? I''m just a little sketchy on how this should work. Brian Hogan Web Development Learning & Technology Services Schofield 3-B University of Wisconsin-Eau Claire 715 836 3585 hoganbp-VnAisaAFmHY@public.gmane.org _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Hogan, Brian P. wrote:> Let''s say for the sake of argument that I wanted to change this code in > > C:\ruby\lib\ruby\gems\1.8\gems\actionpack-1.10.1\lib\action_controller\url_rewriter.rb > > > private > def rewrite_url(path, options) > rewritten_url = "" > unless options[:only_path] > rewritten_url << (options[:protocol] || @request.protocol) > rewritten_url << (options[:host] || @request.host_with_port) > end > > rewritten_url << @request.relative_url_root.to_s unless > options[:skip_relative_url_root] > rewritten_url << path > rewritten_url << ''/'' if options[:trailing_slash] > rewritten_url << "##{options[:anchor]}" if options[:anchor] > > rewritten_url > end > > > How would I do this in my application only? Would I just do > > class UrlRewriter > private > def rewrite_url(path, options) > # my new logic here > rewritten_url > end > End > > And then just require this somewhere? I''m just a little sketchy on how > this should work.I would guess this is the correct way. I always wonder where to put the files with the overridden methods. Is there a standard place to put that so that it gets loaded automaticly?
On 10/26/05, Wiebe Cazemier <halfgaar@gmail.com> wrote:> Hogan, Brian P. wrote: > > Let's say for the sake of argument that I wanted to change this code in > > > > C:\ruby\lib\ruby\gems\1.8\gems\actionpack-1.10.1\lib\action_controller\url_rewriter.rb > > > > > > private > > def rewrite_url(path, options) > > rewritten_url = "" > > unless options[:only_path] > > rewritten_url << (options[:protocol] || @request.protocol) > > rewritten_url << (options[:host] || @request.host_with_port) > > end > > > > rewritten_url << @request.relative_url_root.to_s unless > > options[:skip_relative_url_root] > > rewritten_url << path > > rewritten_url << '/' if options[:trailing_slash] > > rewritten_url << "##{options[:anchor]}" if options[:anchor] > > > > rewritten_url > > end > > > > > > How would I do this in my application only? Would I just do > > > > class UrlRewriter > > private > > def rewrite_url(path, options) > > # my new logic here > > rewritten_url > > end > > End > > > > And then just require this somewhere? I'm just a little sketchy on how > > this should work. > > I would guess this is the correct way. I always wonder where to put the files > with the overridden methods. Is there a standard place to put that so that it > gets loaded automaticly?The ideal place for this type of stuff is in lib/. Just make sure that the dir/file combination has a unique name, because you have to require it from your environment. I used to have in my environment: require 'active_record/nullify_empty_attributes.rb' This was before AR did this automatically :-) (Well, in fact I have, as of yet, been to lazy too do away with this hack ;-) See also: http://wiki.rubyonrails.org/rails/pages/UnderstandingWhatFilesGoesWhere - Rowan -- Morality is usually taught by the immoral. _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails