0

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?

asolberg
  • 6,638
  • 9
  • 33
  • 46
  • Have you done the migration for friendlyID at production? – kiddorails May 17 '14 at 14:06
  • Yep - made sure to do that. – asolberg May 17 '14 at 14:21
  • This is weird. I just recently used FriendlyID for one of my app, and it worked fine on production. Ruling migration out; with this behavior, I can only say that the new build may not be passed to Production. :\ – kiddorails May 17 '14 at 14:23
  • when you say link_to("text", product) how does rails get the URL for product? Thats the heart of the issue here. – asolberg May 17 '14 at 15:10
  • I just have it like this `link_to("Visit", product)`, and in the `show` action - `@product = Product.friendly.find(params[:id]).to_s.downcase` – kiddorails May 17 '14 at 15:18
  • Yep, I have that too. And it works in dev but not in production. So right now I'm looking at polymorphic_routes::polymorphic_url because that's where the URL get's generated in Rails. – asolberg May 17 '14 at 15:23
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/53881/discussion-between-kiddorails-and-asolberg) – kiddorails May 17 '14 at 15:25

1 Answers1

1

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. :)

kiddorails
  • 12,961
  • 2
  • 32
  • 41