Hey guys. I’m having some trouble with a route spec. In routes.rb , I
have:
map.connect ‘foods/search/:name’, :controller => :foods, :action =>
:search
Hey guys. I’m having some trouble with a route spec. In routes.rb , I
have:
map.connect ‘foods/search/:name’, :controller => :foods, :action =>
:search
After reading the rspec-rails 1.2.0 upgrade notes (http://tr.im/K1zx), I
haven’t been able to figure out what I’m doing wrong. Any hints?
Thanks!
Nick
PS: I’m using 1.2.9 and Rails 2.3.4 .
Hi Nick,
You need to add quotes while writing in routs.rb file.
So your route will be define as :
map.connect ‘foods/search/:name’, :controller => ‘foods’, :action =>
‘search’
Now try running the code again.You will see it pass.
Hey guys. I’m having some trouble with a route spec. In routes.rb , I
have:
map.connect ‘foods/search/:name’, :controller => :foods, :action =>
:search
After reading the rspec-rails 1.2.0 upgrade notes (http://tr.im/K1zx), I
haven’t been able to figure out what I’m doing wrong. Any hints?
Thanks!
Nick
PS: I’m using 1.2.9 and Rails 2.3.4 .
Hi Nick,
You need to add quotes while writing in routs.rb file.
So your route will be define as :
map.connect ‘foods/search/:name’, :controller => ‘foods’, :action =>
‘search’
Now try running the code again.You will see it pass.
Thanks for the suggestion, Amit. I changed the symbols to strings.
Unfortunately, the same error is still occurring: http://codepad.org/lck4r1S0
There must be some tiny detail that I’m missing here…
Yes, there must. I think you’ve tried to twice define the route, and
the test shows you which one actually is being used. I’ll suggest
commenting out one of those routes at a time, and see whether the new
test results are illuminating.
There must be some tiny detail that I’m missing here…
Yes, there must. I think you’ve tried to twice define the route, and
the test shows you which one actually is being used. I’ll suggest
commenting out one of those routes at a time, and see whether the new
test results are illuminating.
Randy
I swapped the order of the 2 lines in routes.rb to this:
I guess the distinction is that you generate food_path()'s based on
existing food names, and search comes from users - but you don’t have a
distinct landing page for each food, hence no need for resource-based
routing for foods.
You could define a :show action in your controller, which simply calls
the ‘search’ action.
def show
search
end
Then they’ll have different controller-actions and different paths, yet
the implementations would be identical. And the specs can describe them
distinctly.
I’d be curious if there are other ways to do this.
Hey guys. I have two different paths that lead to the same controller
and action:
map.connect ‘foods/search/:name’, :controller => ‘foods’, :action =>
‘search’
map.food ‘:name’, :controller => ‘foods’, :action =>
‘search’
Unfortunately, the spec for the second route fails because #route_to
finds and uses the first route when generating the path for
:controller => ‘foods’, :action => ‘search’, :name => ‘almonds’