Reputation: 4378
I am having problem with namespaced controller and routing. I have following namespaced route.
namespace :institution do
resources :students
end
along with
resources :students, :only => [] do
resources :college_selections, :only =>[:index, :create, :update]
resources :progress, :only => [:index] do
collection {get 'compare'}
end
resources :marks
end
it generated the following routes
institution_students GET /institution/students(.:format) {:action=>"index", :controller=>"institution/students"}
POST /institution/students(.:format) {:action=>"create", :controller=>"institution/students"}
new_institution_student GET /institution/students/new(.:format) {:action=>"new", :controller=>"institution/students"}
edit_institution_student GET /institution/students/:id/edit(.:format) {:action=>"edit", :controller=>"institution/students"}
institution_student GET /institution/students/:id(.:format) {:action=>"show", :controller=>"institution/students"}
PUT /institution/students/:id(.:format) {:action=>"update", :controller=>"institution/students"}
DELETE /institution/students/:id(.:format) {:action=>"destroy", :controller=>"institution/students"}
I have a students controller inside institution directory in apps directory. And it has following structure.
class Institution::StudentsController < ApplicationController
before_filter :require_login
load_and_authorize_resource
..........
.........
end
Now when i tried to redirect to students show page with a link_to helper method as shown below
<%= link_to "show", institution_student_path(student) %>
then it showed wired kind of link with a period(.) in it. Say the student id is 100 and it generated the routes like this
institution/students/4.100
here 4 is current institution id i guess. Why is such routes being generated.
And when i click on show link it gave me error saying
Expected /home/gagan/projects/App_name/app/Institution/students_controller.rb to define StudentsController
What am i missing here.
Thanks in advance.
Upvotes: 3
Views: 3276
Reputation: 4378
Never mind I got the answer. Actually I was putting institution folder outside controller folder which was the reason that the controller inside this folder are not being recognized. Hence solved the problem.
Upvotes: 1
Reputation: 1439
you should be using
<%= link_to "show", institution_student_path(institution, student) %>
or
<%= link_to "show", institution_student_path(student.institution, student) %>
if there is an association between student and institution.
Upvotes: 1