2012-02-15 12 views
3

名前空間のコントローラとルーティングに問題があります。私は以下の名前空間を持っています。レール3の名前付きコントローラとルーティング

resources :students, :only => [] do 
    resources :college_selections, :only =>[:index, :create, :update] 
    resources :progress, :only => [:index] do 
     collection {get 'compare'} 
    end 
    resources :marks 
    end 

とともに

namespace :institution do 
    resources :students 
    end 

それは私がアプリケーションディレクトリ内の機関ディレクトリ内の学生のコントローラを持って次のルートに

 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"} 

を生成。そしてそれは以下の構造を持っています。私は学生にリダイレクトしようとしたとき、それはそれでピリオド(。)とのリンクの有線種類を示し

<%= link_to "show", institution_student_path(student) %> 

以下のように

class Institution::StudentsController < ApplicationController 
    before_filter :require_login 
    load_and_authorize_resource 
.......... 
......... 
end 

今のlink_toヘルパーメソッドを含むページを示します。生徒IDが100で、このようなルートが生成されたとします。

institution/students/4.100 

ここ4は現在の施設IDです。なぜそのようなルートが生成されているのですか?私はショーのリンクをクリックしたとき

は、そして、それは私がここで行方不明です何

Expected /home/gagan/projects/App_name/app/Institution/students_controller.rb to define StudentsController 

を言って私にエラーを与えました。

ありがとうございます。

答えて

1

私は答えを得ていません。実際に私はこのフォルダ内のコントローラが認識されていない理由として、コントローラフォルダの外に機関フォルダを置いていました。したがって、問題を解決しました。

1

学生と金融機関との間に関連性がある場合は、

<%= link_to "show", institution_student_path(institution, student) %> 

または

<%= link_to "show", institution_student_path(student.institution, student) %> 

を使用する必要があります。

+0

私はあなたが私の質問を完全に理解していないと思う、生成されたルートの行番号5を見てください。私はinstitution_student_path(:student_id)とのリンクを生成しましたが、上記のように間違ったパスを生成しています。何故ですか?私がinstitution_students_pathに行くと、質問の最終行にエラーが表示されます。 – Gagan

関連する問題