[rspec-users] Rails: View specs and implicit parameters in link_to()

Zach Dennis zach.dennis at gmail.com
Sat Nov 22 19:34:34 EST 2008

On Thu, Oct 16, 2008 at 5:31 AM, Matt Wynne <matt at mattwynne.net> wrote:
> Hi all,
> I've been cleaning up our routing file, and removed the default map.connect
> ":controller/:action" route.
> It's thrown up a bunch of sloppy mistakes, which is great, but I also think
> I've found a problem with the view specs.
> We have a generic navbar partial which is rendered in the index page of
> several different controllers. The navbar contains some call to link_to of
> the form:
>        <%= link_to "By Concert", :sort => 'by_concert' %>
> Since I removed the default (catch-all) route, this fails in the view specs:
>> No route matches {:action => "index", :sort => "by_concert"
> At runtime, rails seems to figure out the controller as well, and we get a
> full URL built fine.
> I tried adding this to my specs
>        params[:controller] = "images"
> but nothing changed. I've worked around it by also doing this in the view:
>        <%= link_to "By Concert", :controller => params[:controller], :sort
> => 'by_concert' %>
> This seems kind of dirty... and it's also weird that I can't seem to be able
> to fake the context that the views render in at runtime.
> What do other people do with this sort of problem? Am I missing something
> obvious?

This looks to be solved in in master. See

Zach Dennis

More information about the rspec-users mailing list