简体   繁体   English

rails 3命名空间控制器和路由

[英]rails 3 namespaced controller and routing

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. 我在apps目录的机构目录中有一个学生控制器。 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帮助方法重定向到学生显示页面时,如下所示

<%= 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 假设学生ID为100,它生成了这样的路线

institution/students/4.100 

here 4 is current institution id i guess. 这里4是我猜的当前机构ID。 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. 提前致谢。

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. 如果学生和学校之间存在关联。

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. 因此解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM