1

Alright, either I need to go to bed or change careers. An incredibly simple link_to is failing and I just can't see where.

#routes.rb
resources :wikis

#view.html.haml
= link_to @wiki.title, wiki_path(@wiki)

Errors with:

No route matches {:action=>"show", :controller=>"wikis", :id=>#<Wiki id: 10, created_by_id: 1, ...

Now I'm not doing anything crazy like overriding the primary key; anything.

Here's the associated Wikis#show route in rake routes:

wiki GET    /wikis/:id(.:format)                            {:action=>"show", :controller=>"wikis"}
Matt Darby
  • 6,294
  • 4
  • 27
  • 35

2 Answers2

2

you can try

<%= link_to @wiki.title, @wiki %>

Sergey Kishenin
  • 5,099
  • 3
  • 30
  • 50
1

does it works: wiki_path(@wiki.id) ?

Adrien Rey-Jarthon
  • 1,015
  • 2
  • 9
  • 22
  • This works, but the way I posted above should as well. I have a bunch of existing code I'm not wanting to update unnecessarily either. – Matt Darby Apr 03 '11 at 20:45
  • 1
    I suppose you're not overloading `to_param` on Wiki ? try checking the return value of @wiki.to_param – Adrien Rey-Jarthon Apr 04 '11 at 17:29
  • Looking through the source, :to_param will work regardless of what it returns, so long as it's unique. The issue was that the key I was using in :to_param was nil. – Matt Darby Apr 04 '11 at 22:04
  • ^^ ok, and one quick reminder for all of us: to_param should return a string in order helpers to work properly, so be careful when using non-string field to convert them inside the to_param method. – Adrien Rey-Jarthon Apr 05 '11 at 17:07