undefined local variable or method `articles_path' for #<#:0x39b05f8> and the code is
<h1>New Article</h1>
<%= form_for :article, url: articles_path do |f| %>
<p>
<%= f.label :title %><br>
<%= f.text_field :title %>
Iam new to ruby on rails programming.When i run above code in rails server i got the error as NameError in articles#new.Please give me the answer to resolve the above error.
Controller Code
class ArticlesController < ApplicationController
def new
end
def create
render plain: params[:article].inspect
end
end
Rake Routes
Prefix Verb URI Pattern Controller#Action
articles_new GET /articles/new(.:format) articles#new
article_index GET /article(.:format) article#index
POST /article(.:format) article#create
new_article GET /article/new(.:format) article#new
edit_article GET /article/:id/edit(.:format) article#edit
article GET /article/:id(.:format) article#show
PATCH /article/:id(.:format) article#update
PUT /article/:id(.:format) article#update
DELETE /article/:id(.:format) article#destroy
root GET / welcome#index
I had this problem and realized it was because my routes.rb had
resources :article
Just change it to
resources :articles
and that should fix it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With