Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable :.format routes in rails3

Could you tell me how to disable the .:format options in rails routes? I only need html...

like image 453
BvuRVKyUVlViVIc7 Avatar asked Jan 02 '11 17:01

BvuRVKyUVlViVIc7


People also ask

How do I see Rails routes?

TIP: If you ever want to list all the routes of your application you can use rails routes on your terminal and if you want to list routes of a specific resource, you can use rails routes | grep hotel . This will list all the routes of Hotel.

What are RESTful routes in Rails?

In Rails, a RESTful route provides a mapping between HTTP verbs, controller actions, and (implicitly) CRUD operations in a database. A single entry in the routing file, such as. map.resources :photos. creates seven different routes in your application: HTTP verb.

What is routes in Ruby on Rails?

The routing module provides URL rewriting in native Ruby. It's a way to redirect incoming requests to controllers and actions. It replaces the mod_rewrite rules. Best of all, Rails' Routing works with any web server.

What is namespace in Rails routes?

This is the simple option. When you use namespace , it will prefix the URL path for the specified resources, and try to locate the controller under a module named in the same manner as the namespace.


2 Answers

In 3.1.1 at least you can add , :format => false to the end of the route.

Found here: http://guides.rubyonrails.org/routing.html#request-based-constraints under section 3.11 Route Globbing

eg..

match '*pages' => 'pages#show', :format => false

Which would allow params[:pages] to include a period.

like image 105
Jim Morris Avatar answered Sep 27 '22 22:09

Jim Morris


http://guides.rubyonrails.org/routing.html#request-based-constraints

This will constrain your routes to accept only html format:

constraints :format => "html" do
  resources :posts do
    resources :comments
  end
end

However, it won't remove (.:format) part from your rake routes output.

like image 36
Heikki Avatar answered Sep 27 '22 21:09

Heikki