Hobo Cookbook

View Source



<a> is extended in Rapid to automatically provide URLs for Hobo model routes


The tag behaves as a regular HTML link or anchor if either the href or name attribute is given:

<a href="/admin">Admin</a> -> Output is exactly as provided, untouched by Rapid

If no href or name is given then the context is used to determine the link URL. The helper method object_url is used to construct the URL using restful routing:

If the context is a class then the link will be an index page:

<a with="&BlogPost">My Blog</a> -> <a href="/blog_posts">My Blog</a>

If the context is a hobo model instance then the link will be a show page:

<% blog_post = BlogPost.find(1) %>
<a with="&blog_post">My Blog Post</a> -> <a href="/blog_posts/1">My Blog Post</a>

An action can be provided for an alternative show page:

<a with="&blog_post" action="edit">Edit Post</a> -> <a href="/blog_posts/1/edit">Edit Post</a>

Or a new page if the context is a class:

<a with="&BlogPost" action="new">New Blog Post</a> -> <a href="/blog_posts/new">New Blog Post</a>

Additional Features

  • If the constructed route does not exist then the link will not be created, but the content of the link will still be output. E.g. when /blog_posts does not exist (because the hobo model controller does not exist or the index action is disabled):

      <a with="&BlogPost">My Blog</a> -> My Blog

    when the show action /blog_posts/:id does not exist:

      <a with="&blog_post">My Blog Post</a> -> My Blog Post
  • If no content text is provided then <a> will use the name method on the context to provide the text. E.g.

      <a with="&blog_post"/> -> <a href="/blog_posts/1">My First Blog Post</a>`
      <a with="&BlogPost"/> -> <a href="/blog_posts">Blog Posts</a>`
  • If action="new" then <a> will check that the current user has permission to create the object

  • Several useful classes are added automatically to the output <a>.


  • action: If “new”, triggers the special behaviour listed above. Otherwise, contains the action to be performed on the context. If neither action nor method are specified, the action will be “index” or “show”, as appropriate.

  • to: Use this item as the target instead of the current context.

  • params, query-params: These are appended to the target as a query string after a ”?”. Params are passed as a ruby hash. Example: params="&{id=>17, name=>'joe'}"

  • href, name: If either of these attributes are present, the smart features of this tag are turned off.

  • format: this adds “.#{format}” to the end of the url

  • subsite: routes the URL using the subsite

  • force: overrides the permission check if action is “new”

  • method: “get”, “put”, “post” or “delete”. “get” is the default

Show Source


No comments to display