0

i have two identically controllers routed in the same way :

resources :profile resources :friends 

here are the controllers

class ProfileController < ApplicationController def index @text = "profile" end def show end def new end def create end def edit end def update end def destroy end end class FriendsController < ApplicationController def index @text = "friends" end def show end def new end def create end def edit end def update end def destroy end end 

but when i want to define a menu in the view layout , a problem occurs for the profile controller but not also for the friends controller . Here is the code that generates the error :

<ul id="menu"> <li> <%= link_to "Friends",friends_path %> </li> <li> <%= link_to "Profile", profile_path %> </li> </ul> 

and the error is :

No route matches {:action=>"show", :controller=>"profile"} 

Why is this happening if the controllers and views are identical ?

2 Answers 2

1

It's related to the fact that you've given your Profile controller a singular name and route. You can run rake routes to find out what the route helpers are named. Look for GET /profile, it might be something like index_profile_path or profile_index_path

Edit: more specifically, the error is because it's expecting by default for profile_path to be the helper for showing a certain instance, e.g. profile_path(@profile)

Sign up to request clarification or add additional context in comments.

Comments

0

try using

<%= link_to "Profile", profiles_path %> 

The difference is in the variable name profile s _path. As the path to the index url should be in plural.

You can also see all the routes if your application by running rake routes - it's a live saver to debug routes problems.

1 Comment

no , that is not it .. i've tried it earlier and i've tried it now . i get the error : undefined local variable or method `profiles_path' for #<#<Class:0xa095f74>:0xa0944bc> so i think that this is not the problem

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.