How to customize ids in URLs in your Rails app
15-Feb-2025 42
Rails’ URL helpers allow you to pass in an Active Record object and it will automatically infer the proper URL including the id (e.g. link_to "Profile", @user). How can we get this behavior for custom objects?
Custom objects
Consider a custom Image class. We want URLs to look like /images/cat.gif.
Rails relies on the to_param method to generate identifiers in URLs. If we define it on our custom object it can now be used with link_to just like ActiveRecord objects can.
.
How to customize ids in URLs in your Rails app #ruby #rubydeveloper #rubyonrails #customize #Rails https://rubyonrails.ba/link/how-to-customize-ids-in-urls-in-your-rails-app