Cloud 9 ruby on rails 制作文章时出错
Cloud 9 ruby on rails error while making articles
我收到一条错误消息:
https://i.stack.imgur.com/7mw12.png(这是错误的图片)
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
这是我的 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
我不知道如何制作文章模型,如果我做了,我不知道该放什么...显示 如果你能告诉我如何[在此处输入图片描述][,我将不胜感激1]
我想你还没有在模型文件夹中创建文章模型。因此它无法创建新对象。
在您的模型文件夹中创建一个文件:
class Article < ApplicationRecord
end
然后尝试在 Article
上创建 .new 命令
Article.new
我收到一条错误消息:
https://i.stack.imgur.com/7mw12.png(这是错误的图片)
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
这是我的 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
我不知道如何制作文章模型,如果我做了,我不知道该放什么...显示 如果你能告诉我如何[在此处输入图片描述][,我将不胜感激1]
我想你还没有在模型文件夹中创建文章模型。因此它无法创建新对象。 在您的模型文件夹中创建一个文件:
class Article < ApplicationRecord
end
然后尝试在 Article
上创建 .new 命令Article.new