Skip to content

Commit c7ad0a4

Browse files
committed
use hash argument in redirect
1 parent 7e49d27 commit c7ad0a4

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

README.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ redirect "/new_url"
224224
use permanent redirect
225225

226226
``` ruby
227-
redirect "/new_url", true
227+
redirect "/new_url", :permanent => true
228228
```
229229

230230
## Raising Errors

lib/grape/endpoint.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,11 @@ def error!(message, status=403)
136136
# Redirect to a new url.
137137
#
138138
# @param url [String] The url to be redirect.
139-
# @param permanent [Boolean] Whether use permanent redirect with status code 304.
140-
def redirect(url, permanent=false)
141-
if permanent
139+
# @param options [Hash] The options used when redirect.
140+
# :permanent, default true.
141+
def redirect(url, options = {})
142+
merged_options = {:permanent => false }.merge(options)
143+
if merged_options[:permanent]
142144
status 304
143145
else
144146
if env['HTTP_VERSION'] == 'HTTP/1.1' && request.request_method.to_s.upcase != "GET"

spec/grape/endpoint_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def app; subject end
227227

228228
it "support permanent redirect" do
229229
subject.get('/hey') do
230-
redirect "/ha", true
230+
redirect "/ha", :permanent => true
231231
end
232232
get '/hey'
233233
last_response.status.should eq 304

0 commit comments

Comments
 (0)