Reputation: 6878
It's strange it works on my dev environment but when I deploy it continues to link to the product ID.
I am using Rails 4.04 and the FriendlyId v5 Gem. On development when I do this:
<%= link_to image_tag(product.photos.first.image.url(:feed)), product %>
It generates a picture with a link that looks like this:
http://localhost:3000/products/my-product-slug
But when I deploy to production the same code generates
http://myprodserver.com/products/68
Why would this be happening?
Upvotes: 0
Views: 503
Reputation: 13014
As discussed with you, the problem is that you are explicitly generating the slug
field in your model.
Though you have correctly configured FriendlyID
in your model - but in production, there are still many products for which slug
field may not have value. You need to generate the slugs for them before you can access the route correctly (as intended).
I take that the slug generation part is in some sort of some callback. So, in production, you can do:
Product.find_each(&:save)
to create slugs.
FriendlyID should then work perfectly! :)
Good luck. :)
Upvotes: 1