<%= link_to 'Add new weird stuff', controller: new_article_path %>
and this raises the exception
ActionController::UrlGenerationError in Articles#index
No route matches {:action=>"index", :controller=>"articles/new"}
The helper new_article_path returns 'articles/new'. My routes are these:
welcome_index GET /welcome/index(.:format) welcome#index
articles GET /articles(.:format) articles#index
POST /articles(.:format) articles#create
new_article GET /articles/new(.:format) articles#new
edit_article GET /articles/:id/edit(.:format) articles#edit
article GET /articles/:id(.:format) articles#show
PATCH /articles/:id(.:format) articles#update
PUT /articles/:id(.:format) articles#update
DELETE /articles/:id(.:format) articles#destroy
root GET / welcome#index
My ArticlesController class has a method 'new' with empty body.
The answer is in the error if you look carefully. You want it to link
to controller articles, action new, but the error says that it is
going to controller articles/new. It is because you have told it that
the controller is articles/new, whereas in fact this is the complete
path. You just need
<%= link_to 'Add new weird stuff', new_article_path %>
I’d like to renew this old thread with another question. I’m also a newbie to RoR following the getting_started tutorial now and stuck upon creating new article. Unlike that stated and expected the form_with model renders markup to the same articles/new, not the home. If I specify the url: articles_path in the form helper it posts to #create action then but raises param is missing or the value is empty: article. What am I doing wrong? Is that tutorial page still relevant at all?