The redirect_path plugin builds on top of the path plugin, and allows the r.redirect
method to be passed a non-string object that will be passed to path
, and redirect to the result of path
.
In the second argument, you can provide a suffix to the generated path. However, in this case you cannot provide a non-default redirect status in the same call).
Example:
Foo = Struct.new(:id) foo = Foo.new(1) plugin :redirect_path path Foo do |foo| "/foo/#{foo.id}" end route do |r| r.get "example" do # redirects to /foo/1 r.redirect(foo) end r.get "suffix-example" do # redirects to /foo/1/status r.redirect(foo, "/status") end end
Classes and Modules
Public Class methods
load_dependencies(app)
[show source]
# File lib/roda/plugins/redirect_path.rb 37 def self.load_dependencies(app) 38 app.plugin :path 39 end