config/routes.rb

ActionController::Routing::Routes.draw do |map|
map.posts 'posts', :controller => 'posts', :action => 'create',
:conditions => {:method => :post}
end

POST

% telnet localhost 3000
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying fe80::1...
telnet: connect to address fe80::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
POST /posts HTTP/1.0
Content-Length: 21

hoge=fuga&hoge2=fuga2
HTTP/1.1 200 OK
Etag: "d1a0c9e0358e819fd093bc7ddd19caeb"
Connection: close
Content-Type: text/html; charset=utf-8
Date: Thu, 01 Jul 2010 08:54:17 GMT
Server: WEBrick/1.3.1 (Ruby/1.8.7/2010-06-23)
X-Runtime: 2
Content-Length: 72
Cache-Control: private, max-age=0, must-revalidate
<h1>Posts#create</h1>
<p>Find me in app/views/posts/create.html.erb</p>
Connection closed by foreign host.

GET

% telnet localhost 3000
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying fe80::1...
telnet: connect to address fe80::1: Connection refusedTrying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GET /posts HTTP/1.0

HTTP/1.1 405 Method Not Allowed
Allow: POST
Connection: close
(以下略)

Module: ActionController::Routing

Route conditions

With conditions you can define restrictions on routes. Currently the only valid condition is :method.

  • :method - Allows you to specify which method can access the route. Possible values are :post, :get, :put, :delete and :any. The default value is :any, :any means that any method can access the route.

Comments


Option