0

the application has installed per gemfile.lock

friendly_id (5.1.0)
friendly_id-globalize (1.0.0.alpha2)

the base gem page states "As of version 5.0, Finders are no longer overridden by default. If you want to do friendly finds, you must do Model.friendly.find" while the guide for 5.1 links to the most complete, user-friendly documentation, which states both following forms are possible:

Person.find(82542335)
Person.friendly.find("joe")

Compounding matters the globalize plugin also refers to a compact syntactic version

I18n.locale = :en
Post.find("star-wars")

So there are a few possibilities so wrangle with. The following model set-up:

extend FriendlyId
friendly_id :slug, :use => :globalize

and associated controller action

  def show
    @staticpage = Staticpage.find(params[:slug])
    @the_page = Staticpage.find(2)

only has the find(#{id}) instance variable working, whereas all syntaxes attempted on the first instance variable invariably returns Couldn't find Staticpage with 'id'=

While a working answer would be appreciated, a clarification of uses would be better!

Jerome
  • 5,583
  • 3
  • 33
  • 76
  • I am not certain but I'd suspect the readme for `friendly_id-globalize` hasn't been updated in line with friendly_id 5. In your example code it may not be working because friendly_id overrides `to_param` so it uses the slug as the id in rails. So you want `@staticpage = Staticpage.find(params[:id])` if you've not explicitly passed slug as a parameter to the controller. – j-dexx Feb 15 '16 at 12:07
  • That is a small step.`"id"=>"refrigerazione-condizioni"}` is being passed as a parameter. However AR does not digest it properly: `Couldn't find Staticpage with 'id'=refrigerazione-condizioni`. Attempting, according to the > 5.0 instructions `@staticpage = Staticpage.friendly.find(params[:id])` returns `ActiveRecord::RecordNotFound` – Jerome Feb 15 '16 at 12:16
  • Did you set the locale to the correct locale before running the find? – j-dexx Feb 15 '16 at 12:19
  • Yes, it is set by an application-wide method. As an added bit of info, for example the edit action using what was the original set-up without friendly_id: `@staticpage = Staticpage.find_by_slug!(params[:slug])`properly returns the page – Jerome Feb 15 '16 at 12:57
  • @j-dexx the locale suggestion pointed in the proper general direction. As this was dealing with pre-existing data, the slug field was populated. slug_en not. So, somehow the database needs to be updated with the required values before proceeding (and in the meantime the finds are *not* working => vicious circle!)... which is another issue. – Jerome Feb 16 '16 at 08:17

0 Answers0