(Beginner) ActionController::UrlGenerationError - No route matches

(Using Rails 4.1.1 with Ruby 2.1.1 on Mac OSX 10.6 Snow Leopard)

I’m doing a Rails tutorial (in case you are interested in: It’s
Getting Started with Rails — Ruby on Rails Guides), and I’m stuck on
the following:

I create in some erb file a link using

<%= 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.

I have views/articles/new.html.erb.

When I manually enter the URL http://localhost:3001/articles/new in my
browser, the correct page is shown.

I had expected that my link_to call() would generate a link to that very
page, but instead it throws an exception. Something seems to be missing
here.

Where am I wrong here, and how can I fix it? (I hope the information
provided is complete to answer this question).

try something like this:

<%= link_to t(’.new’, :default => t(“helpers.links.new”)),
new_article_path(article), :class => ‘btn
btn-mini’ %>

Where class =>‘btn btn-mini’ is un type of button when you use bootstrap
theme if you don’t use it try whitout this option.

On 16 May 2014 12:50, Ronald F. [email protected] wrote:

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:

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 %>

Colin

Colin L. wrote in post #1146273:

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 %>

:open_mouth:

Now after you explained it, it became obvious!!

Thanks a lot.

Ronald