[rspec-users] Troubles with route_for

Randy Harmon rjharmon0316 at yahoo.com
Sun Jan 24 13:43:01 EST 2010


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.

Randy



On 1/23/10 7:24 PM, Nick Hoffman wrote:
> 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'
>
> routes.rb: http://codepad.org/CjKRynr5
> specs:     http://codepad.org/838oV3mW
>
> Is there a solution to this problem?
>
> Thanks,
> Nick
>   



More information about the rspec-users mailing list