Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug undefined method form_with error

I'm getting the error:

undefined form_with for #<#<Class:0x7ac62e0>:0x551e5a8> in articles#new

The error occurs in the following file: new.html.erb Which has:

<%= form_with(model: [@article] , local: true) do |f| %>
  <p>
    <%= f.label :title %><enter code here`br>
    <%= f.text_field :title %>
  </p>

And the controller articles_controller.rb has:

class ArticlesController < ApplicationController
  def new
  end
end
like image 431
harshitha mg Avatar asked Sep 21 '17 17:09

harshitha mg


1 Answers

your controller just has new command see sample below for create instance variable @article

articles_controller.rb

class ArticlesController < ApplicationController 
  def new
    @article = Article.new
  end
end

new.html.erb

<%= form_with @article do |f| %>
  <%= f.label "Enter title: " %> 
  <%= f.text_field :title %> 
<% end %>
like image 153
widjajayd Avatar answered Sep 28 '22 05:09

widjajayd