Module: Roda::RodaPlugins::Path
- Defined in:
- lib/roda/plugins/path.rb
Overview
The path plugin adds support for named paths. Using the path class method, you can easily create *_path instance methods for each named path. Those instance methods can then be called if you need to get the path for a form action, link, redirect, or anything else. Example:
plugin :path
path :foo, '/foo'
path :bar do ||
"/bar/#{.id}"
end
route do |r|
r.post 'bar' do
= Bar.create(r.params['bar'])
r.redirect ()
end
end
The path method accepts the following options:
- :add_script_name
-
Prefix the path generated with SCRIPT_NAME.
- :name
-
Provide a different name for the method, instead of using
*_path. - :url
-
Create a url method in addition to the path method, which will prefix the string generated with the appropriate scheme, host, and port. If true, creates a
*_urlmethod. If a Symbol or String, uses the value as the url method name. - :url_only
-
Do not create a path method, just a url method.
Note that if :add_script_name, :url, or :url_only is used, this will also create a _*_path method. This is necessary in order to support path methods that accept blocks, as you can’t pass a block to a block that is instance_execed.
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- DEFAULT_PORTS =
{'http' => 80, 'https' => 443}.freeze