I think it is a routing issue where the controller is not matched properly. I am confused because there is clearly a new
action in my ComicTitlesController
.
Here is the error I receive when I load the home page, which has the new_user_comic_title_path
in the navbar:
Routing Error
No route matches {:action=>"new", :controller=>"comic_titles"}
Try running rake routes for more information on available routes.
In my views:
<li><%= link_to 'Publish' , new_user_comic_title_path %></li>
The ComicTitles
controller:
def new
@user = current_user
@comic_title = @user.comic_titles.new
end
Note that ComicTitle
is nested under User
. Here is the route file:
resources :users, shallow: true do
resources :comic_titles
end
When I run 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
Since you have a nested route, I believe the route is expecting a user_id parameter.
In your link_to helper try adding the following:
<li><%= link_to 'Publish' , new_user_comic_title_path(user_id: current_user.id) %></li>