Lucky automatically generates some helpers for generating routes to your actions.
You can access them as class methods on the action itself. They are:
route- returns a
Lucky::RouteHelperobject that contains the path, HTTP method, and the full URL as methods
with- an alias for
routethat is used for passing parameters.
path- returns a string of just the path.
url- returns a string with the whole URL including query params.
url_without_query_params- will return the URL but without query params.
# src/actions/projects/users/index.cr class Projects::Users::Index < BrowserAction get "/projects/:project_id/users" do plain_text "Users" end end
From your pages or components, you can use these with the
class Projects::Users::ShowPage < MainLayout def content # <a href="/projects/my_project_id/users">Back to Users Index</a> link "Back to Users Index", to: Projects::Users::Index.with(project_id: "my_project_id") end end
Projects::Users::Index.with(project_id: "my_project_id") returns a
object that gives you access to a few methods:
These values are based on the action class this route points to.
Learn more about using the routes in the Pages guide.
In a web page, an anchor is a an element you can use to take a user to a specific part of a page. For example, we use this to link to different parts of a guide page.
path method takes an
def content # href="/guides/making-tacos#cheeses" link "See Section 2 of the guide", to: Guides::Show.with(id: "making-tacos", anchor: "cheeses") end
If you need to pass arbitrary query params, or just need the path as a string,
you can use the
url methods directly. Note that
link doesn’t take a
so you would need to use the
a() HTML helper method directly.
def content a "Search again", href: Search::Index.path + "?a=1&b=2" end