Sology / maily_herald-webui

Web interface for MailyHerald - Ruby on Rails email processing solution.
http://mailyherald.org
Other
20 stars 17 forks source link

Be careful if you use Friendly IDs #7

Open aldefouw opened 7 years ago

aldefouw commented 7 years ago

I couldn't figure out why the user interface wasn't working on Rails 5.

But I figured out a fix.

The source of the issue was friendly_id gem that I had installed that allows for user friendly slugs in place of the standard ID URLs. So if you aren't using friendly_id gem - this post is useless to you.

If you are using it, this might save you some time though.

The problem is that the smart_listing gem that renders many of the areas of this maily_herald_webui gem uses automatic defined paths - so it would automatically output the slugs in the URL instead of the ID. (This is correct in almost every case because you generally have control over the controllers ...)

This would be fine - but the controllers in this gem are using .find instead of friendly.find.

My solution?

I over-wrote the finder method in my User model.

def self.find(*args)
    self.friendly.find(*args)
end

This was the cleanest way to do it. I didn't want to override every single controller action that needed friendly.find.

UPDATE: As it turns out, the version of Friendly ID I was running had a bug. In version 5+, you are supposed to be able to add some extenders to your model like so:

class ModelName
      extend FriendlyId
      friendly_id :name, :use => [:slugged, :finders]
end

I was running an out of date version of the gem. So the cleanest fix is to update the gem. Easy!