Skip to content

Commit

Permalink
use hash argument in redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
allenwei committed Apr 30, 2012
1 parent 7e49d27 commit c7ad0a4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ redirect "/new_url"
use permanent redirect

``` ruby
redirect "/new_url", true
redirect "/new_url", :permanent => true
```

## Raising Errors
Expand Down
8 changes: 5 additions & 3 deletions lib/grape/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,11 @@ def error!(message, status=403)
# Redirect to a new url.
#
# @param url [String] The url to be redirect.
# @param permanent [Boolean] Whether use permanent redirect with status code 304.
def redirect(url, permanent=false)
if permanent
# @param options [Hash] The options used when redirect.
# :permanent, default true.
def redirect(url, options = {})
merged_options = {:permanent => false }.merge(options)
if merged_options[:permanent]
status 304
else
if env['HTTP_VERSION'] == 'HTTP/1.1' && request.request_method.to_s.upcase != "GET"
Expand Down
2 changes: 1 addition & 1 deletion spec/grape/endpoint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def app; subject end

it "support permanent redirect" do
subject.get('/hey') do
redirect "/ha", true
redirect "/ha", :permanent => true
end
get '/hey'
last_response.status.should eq 304
Expand Down

0 comments on commit c7ad0a4

Please sign in to comment.