0

I am trying to create a custom route that indexes reviews by a scope of shop_id

I have this in my routes.rb:

get '/reviews/:shop_id'   => 'reviews#index',         :as => :reviews

And this output from my rake routes:

reviews GET    /reviews/:shop_id(.:format)       reviews#index

And just to be complete, here is my ReviewsController:

class ReviewsController < BaseController
  def index
    @shop = Shop.find params[:shop_id]
    @reviews = @shop.reviews.all
  end
end

When I try to load http://testshop.dev:3000/reviews/2 I get this error:

No route matches [GET] "/reviews/2"

Why? And how do I fix it?

Marco Prins
  • 7,189
  • 11
  • 41
  • 76
  • How does the basic routing for reviews look like? Doesn't this form get into naming issues with the custom show? – Albin Oct 21 '14 at 12:37
  • There's no other routing for reviews – Marco Prins Oct 21 '14 at 12:38
  • i tried a similar setup and it seemed to work for me, could you paste your complete routes file (only the lines that are not commented of course) – rik.vanmechelen Oct 21 '14 at 18:21
  • try [http://stackoverflow.com/questions/8718093/routing-in-rails-dots-in-url][1] [1]: http://stackoverflow.com/questions/8718093/routing-in-rails-dots-in-url – JackyJohnson Dec 24 '14 at 07:20

1 Answers1

0

For me it was a completely different reason. I had a basic form_tagwhich had a /forgot-password action.

I was missing the leading /, so when the form submitted, it'd point to: /forgot-password/forgot-password, messing up the /forgot-password/:attribute in my route!

Qasim
  • 1,554
  • 1
  • 13
  • 22