0

我的应用程序有问题,当我将路径 student_postulations_path 放在导航栏中时崩溃:S。

我在我的route.rb

resources :students do
    resources :postulations
  end

我的应用程序说这个错误

No route matches {:controller=>"postulations"}

我的观点

<% elsif student_signed_in? %>
  <% menu_group :pull => :right do %>
    <%= menu_item "Postulaciones", student_postulations_path %>
    <%= menu_divider %>
    <%= drop_down current_student.email do %>
      <%= menu_item "Logout", destroy_student_session_path, :method => :delete %>
    <% end %>
  <% end %>
<% else %>

当我使用 rake 路线时:

student_postulations GET    /students/:student_id/postulations(.:format)          postulations#index
                           POST   /students/:student_id/postulations(.:format)          postulations#create
   new_student_postulation GET    /students/:student_id/postulations/new(.:format)      postulations#new
  edit_student_postulation GET    /students/:student_id/postulations/:id/edit(.:format) postulations#edit
       student_postulation GET    /students/:student_id/postulations/:id(.:format)      postulations#show
                           PUT    /students/:student_id/postulations/:id(.:format)      postulations#update
                           DELETE /students/:student_id/postulations/:id(.:format)      postulations#destroy

我的模特学生和假设:

class Student < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :token_authenticatable, :confirmable,
  # :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable,
         :recoverable, :rememberable, :trackable, :validatable

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :password, :password_confirmation, :remember_me, :nombre, :rol,
                    :prioridad, :resumen, :categoria, :foto
  # attr_accessible :title, :body

  has_many :postulations
end

class Postulation < ActiveRecord::Base
  attr_accessible :status, :student_id

  belongs_to :student
end

我不明白我的错误......我的事情没问题。请帮忙!:)。

谢谢

4

1 回答 1

0

在嵌套资源路由中,您将获得

student_postulations GET    /students/:student_id/postulations(.:format) 

因此,在您看来,您需要将 @student 对象传递给student_postulations_path(@student)

助手喜欢student_postulations_pathstudent_postulations_url将 Student 的实例作为第一个参数student_postulations_path(@student)来查找 student 的记录。

您可以从指南中获取更多信息

所以你的链接路径将是

<%= menu_item "Postulaciones", student_postulations_path(current_student) %>
于 2013-10-31T08:10:40.487 回答