'Can I use a different fall back parameter if the params[:id] isn't the record ID?
I'd like to start using friendly IDs, but have legacy URLs that use the item_id column rather than id. How do I configure FriendlyId so that
class Item < ActiveRecord::Base
extend FriendlyId
friendly_id :name
end
@item = Item.friendly.find "Sneed"
# But I also need Item.friendly.find(1) to find the Item with `item_id = 1`, not `id = 1`.
The find(1) still needs to find the record with id = 1 though. That is, I want to replace the current @item = Item.find_by(item_id: params[:id]) with @item = Item.friendly.find(params[:id])
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
