1

I have a nested rout for toys and then toys will have reviews. The toys works fine with friendly_id but going to website.com/toys/toy-name/reviews/new brings up

Couldn't find Toy without an ID

My routes file looks like this

 resources :toys do
   resources :reviews, except: [:show, :index]
 end

The reviews controller has a set_toy method that is called before_action and is where the error is occurring. The method looks like

 def set_toy
  @toy = Toy.friendly.find(params[:id])
end

The toys controller has a similar method called toy_params that has exactly the same contents.

I can't see why the reviews controller cannot find the toy ID as I have passed it in with friendly.find.

Thank you

Tom
  • 2,543
  • 3
  • 21
  • 42

1 Answers1

3

You will need

 def set_toy
   @toy = Toy.friendly.find(params[:toy_id])
 end

in your reviews controller.

Edward
  • 3,429
  • 2
  • 27
  • 43