URLs
Standard URLs
The format of the standard urls can be configured using url_format
:
What parameters can go in the url format string?
Anything.
:job
is always present, and if not specified in the url_format
, is appended as a query parameter.
Parameters are taken from the Job object’s url_attributes
object (which is like an OpenStruct).
With url_format "/:a/:b-:c.:d"
:
If the parameter is not present, the segment simply doesn’t appear (also the preceding delimiter character, e.g. “/”, “-“ or “.”, is removed)
Passing in attributes
url_attributes
can be overridden by passing in attributes in the call to url
.
With url_format "/:a"
:
How does this relate to models?
When using models you don’t deal with url_attributes
directly. Instead, this is populated from the model’s magic attributes (see Models for more details).
Let’s imagine we have a model
and a url_format "/stuff/:job/:width/:name"
Then with only a photo_uid
column:
With columns photo_uid
, photo_name
With columns photo_uid
, photo_name
, photo_width
Parameters can be overridden in in the same way as before
Special parameters
:job
This encodes all the information about the job and will always be present.
If not specified in the url_format
string it will be added as a query parameter.
:name
, :basename
and :ext
:basename
and :ext
are taken from :name
, so you can split them in the url.
For example, with url_format "/:basename-:width.:ext"
Processors changing URL parameters
Processors can optionally update url_attributes
. For example, the imagemagick encode processor updates the file extension (if using :ext
or :name
)
For example, with url_format "/:name"
and Person
model with columns image_uid
and image_name
See Processors for more details.
Host
By default all URLs are relative. You can set a host for the urls in configure
…or by passing as an argument…
Path Prefix
A url_format
like "/media/:job"
will generate URLs like /media/W1s...
and in turn match any incoming ones that look like /media/...
.
If, for whatever reason, you need the generated URLs to have a further prefix (such as when the app is mounted under a subdirectory), you can use url_path_prefix
…or…
Remote URLs
If the datastore supports it, you can get the URL for serving directly from the data store using
or from a model attachment
The File, S3 and Couch data stores support this, as well as any others that implement the correct interface as per the data stores doc.
Rails custom URLs
See Using with Rails
Derived from theme by orderedlist