How can I generate a link/route/path in Roda?

630 Views Asked by At

How can I generate a path or URL in a view in Roda?

Will I need to use a plugin? If not, how else? Or will I have to hard-code urls/paths?

In Rails I'd do this way:

<%= home_about_path %>
1

There are 1 best solutions below

1
On

To just generate urls based on set semantics, you want the path plugin.

Usage looks something like this:

App < Roda
  plugin :path

  path :post do |post|
    "/blog/#{post.id}"
  end
end

And then, in your templates similarly to how you would use something_path in Rails:

<a href="<%= post_path(@post) %>" class="btn"><%= @post.title %></a>