Skip to content

Instantly share code, notes, and snippets.

@josefarias
josefarias / _nav.html.erb
Last active May 30, 2024 20:26
Rails dropdown component using helpers and Tailwind
<nav class="flex justify-end w-full px-4">
<%= dropdown do %>
<%= dropdown_link_to "Profile", edit_user_registration_path %>
<%= dropdown_link_to "Password", edit_account_password_path %>
<%= dropdown_link_to "Social Accounts", social_accounts_path %>
<%= dropdown_link_to "Accounts", accounts_path %>
<%= dropdown_link_to "Billing", subscriptions_path %>
<%= dropdown_link_to "Other Settings", other_settings_path %>
<%= dropdown_button_to "Log out", destroy_user_session_path, method: :delete %>
module AccountSlug
PATTERN = /(\d{7,})/
FORMAT = '%07d'
def self.decode(slug) slug.to_i end
def self.encode(id) FORMAT % id end
# We're using account id prefixes in the URL path. Rather than namespace
# all our routes, we're "mounting" the Rails app at this URL prefix.
#