我认为这是控制器未正确匹配的路由问题。我很困惑,因为new
我的ComicTitlesController
.
这是我在加载主页时收到的错误,该主页new_user_comic_title_path
在导航栏中有:
Routing Error
No route matches {:action=>"new", :controller=>"comic_titles"}
Try running rake routes for more information on available routes.
在我看来:
<li><%= link_to 'Publish' , new_user_comic_title_path %></li>
ComicTitles
控制器:
def new
@user = current_user
@comic_title = @user.comic_titles.new
end
请注意,ComicTitle
它嵌套在User
. 这是路由文件:
resources :users, shallow: true do
resources :comic_titles
end
当我运行时rake routes
:
user_comic_titles GET /users/:user_id/comic_titles(.:format) comic_titles#index
POST /users/:user_id/comic_titles(.:format) comic_titles#create
new_user_comic_title GET /users/:user_id/comic_titles/new(.:format) comic_titles#new
edit_comic_title GET /comic_titles/:id/edit(.:format) comic_titles#edit
comic_title GET /comic_titles/:id(.:format) comic_titles#show
PUT /comic_titles/:id(.:format) comic_titles#update
DELETE /comic_titles/:id(.:format) comic_titles#destroy