0

Having an issue with my routes that is confusing me. Basically I have a user Has_many workers and a worker belongs_to a user active record setup. So I wanted to do nested routes. Below is my routes file

resources :users do
 resources :workers
end 
resources :sessions, only: [:new, :create, :destroy]
root to: 'info_pages#home'
match '/contact', to: 'info_pages#contact'
match '/about', to: 'info_pages#about'
match '/signup', to: 'users#new'
match '/signin', to: 'sessions#new'
match '/signout', to: 'sessions#destroy', via: :delete 
match '/pools', to: 'pools#new'
match '/settings', to: 'info_pages#settings'

I run rake routes and I see all the nested routes

I went in to my worker controller and have this code

class WorkersController < ApplicationController
 def new
 end

 def show
 end

 def update
 end

 def create
 end

end

Now when I try to load the page with this link

<li><%= link_to "Workers", new_user_worker_path %></li>

The load fails saying "No route matches {:action=>"new", :controller=>"workers"}"

Im not sure why its failing on this route when I clearly have it defined in the routes file and Maybe my controller isn't setup correctly for the nested routes. Thank you!

4

2 回答 2

3

我认为您缺少user变量

<li><%= link_to "Workers", new_user_worker_path(@user) %></li>

或者为了设计你可能想要

<li><%= link_to "Workers", new_user_worker_path(current_user) %></li>
于 2013-06-12T18:33:29.520 回答
0

你能帮我们一个忙并运行“rake routes”来查看输出吗?这应该告诉您您的系统实际上按照定义考虑了哪些路线。

于 2013-06-12T18:44:15.900 回答