How can I create a Rails 3 route that will match all requests and direct to one resource / page?
Rails needs to bind the url parameters to a variable, try this:
match '*foo' => 'content#holding'
If you also want to match /
, use parenthesis to specify that foo
is optional:
match '(*foo)' => 'content#holding'
Rails how to make a route that catches all paths EXCEPT one
In the routes, the order matters.
Try to put your wildcard constraint on the bottom of routes file.
Rails3 routing: how to direct two requests to a single entry point
Assume you are using resources routes just like this one:
# routes.rb
resources :tags
This will create new and create for you.
Suppose you only want new maps to edit, but remaining create unchanged, use the following:
get "/tags/new" => "tags#edit", :as => :new_tag_path
resources :tags
The order is important. The upper one will be matched first. And so if the path is /tags/new
, it will be routed to edit action. And because it is matched already, it won't go down and so although resources :tags
defines also the /tags/new
to new action, no routing will be successfully matched.
So adding the only one line is ok.
Rails 3 helper for match route
you can try
match 'accounts/:account_type/:account_id/edit_account', to: 'accounts#edit_account', as: 'edit_account_accounts'
for more help see The Lowdown on Routes in Rails 3
Route all the URLs starting with a specific word to one specific controller
you can add the following to your route
match '/GitRepos/*path' => 'markdowns#view'
How do I limit rails route wildcard to 1 directory?
Solved it with a regex:
'match "/*path" => 'home#index', :path => %r([a-zA-z0-9]*)'
Overriding a resource route to / (root) in Rails3: not changing the path helper?
Thank you for your answers, it helped me find the exact solution to my question:
resources :subscribers, :only => [:new, :create], :path => '', :path_names => {:new => ''}
Tested and working on Rails 3 :)
Rails, how to get the route name from the actual request (routing reverse lookup)
IMHO you could use the code explained by KinOfCain on How can I find out the current route in Rails?
Rails.application.routes.router.recognize(request){ |route, matches, parameters| puts route.name }
The router is not storing the route recognized in any place at least I wasn't able to find it
Related Topics
Initializing Instance Variable as an Array - Ruby
Generating Sequential Numbers in Multi-User Saas Application
How to Send Mail with Ruby Over Smtp with Ssl (Not with Rails, No Tls for Gmail)
Ruby on Rails Collection Select - How to Pre-Select the Right Value
Sass: Dealing with The Ie 4095 Selectors Per Stylesheet Restriction
How to Make Block Local Variables the Default in Ruby 1.9
Rails 3/ Git/ Bundler Fatal Could Not Parse Object
When Installing Gems "Error: Permission Denied Rb_Sysopen" Arch Linux
Why Is a String Key for a Hash Frozen
Celluloid Async Inside Ruby Blocks Does Not Work
Rails Installation Error :The 'Atomic' Native Gem Requires Installed Build Tools
Simple_Form with Bootstrap Check Box
Using Ruby 2.0 on Amazon Opsworks