Search code examples
ruby-on-railsrubycloud9-idecloud9

Cloud 9 ruby on rails error while making articles


I am getting an error that says:

https://i.sstatic.net/7mw12.png (this is the image of the error)

new.html.erb

<h1>  Create an article  </h1>
<%= form_for @article do |f| %>
<p>
<%= f.label :title %>
<%=f.text_field :title %>
</p>
<% end %>

articles_controller.rb

class ArticlesController < ApplicationController    

def new
@article = Article.new  

end

end 

this is my routes.rb

Rails.application.routes.draw do
# The priority is based upon order of creation: first created -> highest 
priority.
# See how all your routes lay out with "rake routes".
# You can have the root of your site routed with "root"
# root 'welcome#index'
root 'pages#home'
get 'about', to: 'pages#about'
resources :articles

I don't know how to make the article model and if I did I wouldn't know what to put in there... show I would appreciate it if you showed me how [enter image description here][1]


Solution

  • I think you have not created Article model in models folder. Therefore it is not able to create a new object. Create this a file in your models folder:

    class Article < ApplicationRecord
    
    end
    

    and then try to create .new command on Article

    Article.new