1
votes

When I go to localhost:3000/levels/blah-blah-blah-blah.stuff-stuff

It gives me an ActiveRecord::RecordNotFound error.

I checked the params hash and it gives this:

{"action"=>"show", "controller"=>"levels", "id"=>"blah-blah-blah-blah", "format"=>"stuff-stuff"}

in routes.rb:

resources :levels, only: [:index, :show]

match '*levels' => 'levels#show', :format => false, :via => :get

Instead of match, I tried this and it didn't work either:

get "/levels/:id", to: "levels#show", :format => false
2
Leave your routes as it was.SSR
hey SSR gives the same error when I leave my routes as it was.Pavan Katepalli

2 Answers

1
votes

Find this line

@level = Level.find(params[:id])

replace it with

@level = Level.friendly.find(params[:id])

As friendly Id can understand your url approach to to fetch record.

Inside your model/level.rb should be there to use.

extend FriendlyId
friendly_id :name, use: :slugged
0
votes

I ended up doing this to get the period in the url. Rails 4 wasn't cooperating with :format => false in the routes.

def set_level
  # hack to get period in the url
  @level = Level.friendly.find(params[:id] + "." + params[:format])
end