简体   繁体   中英

friendlyid for custom url not working

I'm having a Offer model and having custom url like:

get "all-offers/:id"=> "offers#aff_offers"

How to use friendly id for this custom url. Note- Already done required migration in offer model and added this two line in offer model

 extend FriendlyId
 friendly_id :offer_name, use: :slugged 

I believe FriendlyID adds a field called slug to your model. So, it is quite easy to work with this. In your offers controller under your aff_offers action just do the following:

def aff_offers
  offer = Offer.find_by(slug: params[:id])
end

This will let something like /all-offers/boats-half-off look up an offer with slug having the value of "boats-half-off"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM