module

Lucky::UrlHelpers

Instance methods

current_page?(value : String, check_query_params : Bool = false) : Bool

Tests if the given path matches the current request path.

# Let's say we are visiting https://example.com/shop/products?order=desc&page=1
current_page?("/shop/checkout")
# => false
current_page?("/shop/products")
# => true
current_page?("/shop/products/")
# => true
current_page?("/shop/products?order=desc&page=1")
# => true
current_page?("/shop/products", check_query_params: true)
# => false
current_page?("/shop/products?order=desc&page=1", check_query_params: true)
# => true
current_page?("https://example.com/shop/products")
# => true
current_page?("https://example.io/shop/products")
# => false
current_page?("https://example.com/shop/products", check_query_params: true)
# => false
current_page?("https://example.com/shop/products?order=desc&page=1")
# => true
Source
current_page?(action : Lucky::Action.class | Lucky::RouteHelper, check_query_params : Bool = false) : Bool

Tests if the given path matches the current request path.

# Visiting https://example.com/pages/123
current_page?(Pages::Show.with(123))
# => true
current_page?(Posts::Show.with(123))
# => false
# Visiting https://example.com/pages
current_page?(Pages::Index)
# => true
current_page?(Blog::Index)
# => false
# Visiting https://example.com/pages?page=2
current_page?(Pages::Index.with)
# => true
current_page?(Pages::Index.with(page: 2))
# => true
current_page?(Pages::Index.with, check_query_params: true)
# => false
current_page?(Pages::Index.with(page: 2), check_query_params: true)
# => true
Source
previous_url(fallback : Lucky::Action.class | Lucky::RouteHelper) : String

Returns the url of the page that issued the request (the referrer) if possible, otherwise redirects to the provided default fallback location.

The referrer information is pulled from the 'Referer' header on the request. This is an optional header, and if the request is missing this header the fallback will be used.

Ex. within a Lucky Page, previous_url can be used to provide an href to an anchor element that would allow the user to go back.

a "Back", href: previous_url(fallback: Users::Index)
Source