--------------code-begin---------------- # Allow the metal piece to run in isolation require(File.dirname(__FILE__) + "/../../config/environment") unless defined?(Rails) class Accelerator def self.call(env) if env["PATH_INFO"] =~ /^\/accelerator/ [200, {"Content-Type" => "text/html"}, ["Hello, World!"]] else [404, {"Content-Type" => "text/html"}, ["Not Found"]] end end end --------------code-end------------------ with the code i can process every request without configure rails router. how can i do the same thing in rails3? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Conrad Taylor
2011-Aug-04 10:40 UTC
Re: Metal - How can i do to implement the same effect in Rails3?
On Thu, Aug 4, 2011 at 12:09 AM, Quon <ixitle-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> --------------code-begin---------------- > # Allow the metal piece to run in isolation > require(File.dirname(__FILE__) + "/../../config/environment") unless > defined?(Rails) > > class Accelerator > def self.call(env) > if env["PATH_INFO"] =~ /^\/accelerator/ > [200, {"Content-Type" => "text/html"}, ["Hello, World!"]] > else > [404, {"Content-Type" => "text/html"}, ["Not Found"]] > end > end > end > --------------code-end------------------ > with the code i can process every request without configure rails > router. how can i do the same thing in rails3? > >Quon, the cool thing about Rails 3 is that the router can accept any Rack application. Thus, one can do the above in Rails 3 as follows: routes.rb: root :to => Accelerator match '':controller(/:action(/:id(.:format)))'' => Accelerator application.rb: config.autoload_paths += %W(#{config.root}/lib) config.autoload_paths += Dir["#{config.root}/lib/**/"] lib/accelerator.rb: class Accelerator def self.call(env) if env["PATH_INFO"] =~ /^\/accelerator/ [200, {"Content-Type" => "text/html"}, ["Hello, World!"]] else [404, {"Content-Type" => "text/html"}, ["Not Found"]] end end end This is one way to do it but I''m sure it''s a Rails 3 way to DRY up the routes. Good luck, -Conrad> -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Quon
2011-Aug-05 03:35 UTC
Re: Metal - How can i do to implement the same effect in Rails3?
Thank you for your help, I think it is what i need. On Aug 4, 6:40 pm, Conrad Taylor <conra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Thu, Aug 4, 2011 at 12:09 AM, Quon <ixi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > --------------code-begin---------------- > > # Allow the metal piece to run in isolation > > require(File.dirname(__FILE__) + "/../../config/environment") unless > > defined?(Rails) > > > class Accelerator > > def self.call(env) > > if env["PATH_INFO"] =~ /^\/accelerator/ > > [200, {"Content-Type" => "text/html"}, ["Hello, World!"]] > > else > > [404, {"Content-Type" => "text/html"}, ["Not Found"]] > > end > > end > > end > > --------------code-end------------------ > > with the code i can process every request without configure rails > > router. how can i do the same thing in rails3? > > Quon, the cool thing about Rails 3 is that the router can accept any Rack > application. Thus, one can do the above in Rails 3 as follows: > > routes.rb: > > root :to => Accelerator > match '':controller(/:action(/:id(.:format)))'' => Accelerator > > application.rb: > > config.autoload_paths += %W(#{config.root}/lib) > config.autoload_paths += Dir["#{config.root}/lib/**/"] > > lib/accelerator.rb: > > class Accelerator > def self.call(env) > if env["PATH_INFO"] =~ /^\/accelerator/ > [200, {"Content-Type" => "text/html"}, ["Hello, World!"]] > else > [404, {"Content-Type" => "text/html"}, ["Not Found"]] > end > end > end > > This is one way to do it but I''m sure it''s a Rails 3 way to DRY up the > routes. > > Good luck, > > -Conrad > > > > > > > > > -- > > You received this message because you are subscribed to the Google Groups > > "Ruby on Rails: Talk" group. > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group at > >http://groups.google.com/group/rubyonrails-talk?hl=en.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.