views:

68

answers:

2

First of all, Happy Thanksgiving.

So my issue is with my routes, I'm not clear on why id param actually contains the entire object. Rails gives me this error:

user_url failed to generate from {:action=>"show", :controller=>"users", :id=>#<User id: 19, username: "Dr. Dorothy Buckridge", email: "[email protected]", crypted_password: nil, password_salt: nil, persistence_token: nil, created_at: "2009-11-10 19:38:31", updated_at: "2009-11-10 19:38:31", perishable_token: "", color: nil>}, expected: {:action=>"show", :controller=>"users"}, diff: {:id=>#<User id: 19, username: "Dr. Dorothy Buckridge", email: "[email protected]", crypted_password: nil, password_salt: nil, persistence_token: nil, created_at: "2009-11-10 19:38:31", updated_at: "2009-11-10 19:38:31", perishable_token: "", color: nil>}

The error occurs on this line:

<%= link_to recipe.user.username, recipe.user, :class => "user" %>

Any Idea? It seems like it should only be generating the id of the object for that attribute.

My controller in question is:

def index
  @recipes = Recipe.search params[:search], :field_weights => { :name => 20, :description => 10 }
end

Can't really see what the issue is.

+4  A: 

Did you override to_params in the User model or any class that it inherits?

You can force the id with this:

 <%= link_to recipe.user.username, user_url(recipe.user.id), :class => "user" %>
EmFi
+2  A: 

This is a wild guess, but I had a similar issue when I typed map.resource :user instead of map.resources :users in the routes.rb

Otherwise validate against EmFi's naswer.

Marcel J.
this wasn’t the case but good idea to check, thanks!
Joseph Silvashy