mirror of
https://github.com/sinatra/sinatra
synced 2023-03-27 23:18:01 -04:00
Documentation for condition. Fixes GH #15.
This commit is contained in:
parent
33affbf264
commit
726feeb4ee
1 changed files with 28 additions and 0 deletions
28
README.rdoc
28
README.rdoc
|
@ -81,6 +81,8 @@ Or with a block parameter:
|
|||
"Hello, #{c}!"
|
||||
end
|
||||
|
||||
=== Conditions
|
||||
|
||||
Routes may include a variety of matching conditions, such as the user agent:
|
||||
|
||||
get '/foo', :agent => /Songbird (\d\.\d)[\d\/]*?/ do
|
||||
|
@ -91,6 +93,32 @@ Routes may include a variety of matching conditions, such as the user agent:
|
|||
# Matches non-songbird browsers
|
||||
end
|
||||
|
||||
Other available conditions are `host_name` and `provides`:
|
||||
|
||||
get '/', :host_name => /^admin\./ do
|
||||
"Admin Area, Access denied!"
|
||||
end
|
||||
|
||||
get '/', :provides => 'html' do
|
||||
haml :index
|
||||
end
|
||||
|
||||
get '/', :provides => ['rss', 'atom', 'xml'] do
|
||||
builder :feed
|
||||
end
|
||||
|
||||
You can easily define your own conditions:
|
||||
|
||||
set(:probability) { |value| condition { rand <= value } }
|
||||
|
||||
get '/win_a_car', :probability => 0.1 do
|
||||
"You won!"
|
||||
end
|
||||
|
||||
get '/win_a_car' do
|
||||
"Sorry, you lost."
|
||||
end
|
||||
|
||||
== Static Files
|
||||
|
||||
Static files are served from the <tt>./public</tt> directory. You can specify
|
||||
|
|
Loading…
Add table
Reference in a new issue