How to get composite keys to play with Rails view helpers
23-May-2025 43
We’ve seen in a previous article how making your object ActiveModel-compatible allows it to play natively with Rails’ URL helpers. What about a more complicated case: you have a custom in-memory object that doesn’t have a single primary key but instead relies on several attributes for identity. How can this plug into the Rails helper ecosystem?
The to_key method is what you’re looking for. It drives bothto_paramwe’ve seen before, anddom_id which is realy useful if working with Hotwire.
How to get composite keys to play with Rails view helpers #ruby #rubydeveloper #rubyonrails #composite #Rails #helpers https://rubyonrails.ba/link/how-to-get-composite-keys-to-play-with-rails-view-helpers