Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined local variable or method `articles_path'

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
like image 571
Venkatesh Mandadi Avatar asked May 04 '26 17:05

Venkatesh Mandadi


1 Answers

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.

like image 97
LakeHMM Avatar answered May 06 '26 05:05

LakeHMM