【问题标题】:Cloud 9 ruby on rails error while making articles制作文章时Cloud 9 ruby​​ on rails错误
【发布时间】:2017-08-10 23:47:33
【问题描述】:

我收到一条错误消息:

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 

这是我的路线.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 &lt; ApplicationRecord; end?

标签: ruby-on-rails ruby cloud9-ide cloud9


【解决方案1】:

我认为您还没有在模型文件夹中创建文章模型。因此它无法创建新对象。 在您的模型文件夹中创建一个文件:

class Article < ApplicationRecord

end

然后尝试在文章上创建 .new 命令

Article.new

【讨论】:

  • 所以我必须在我的模型文件夹中创建一个articles.rb 文件吗?
  • 我尝试了我所理解的答案:class Article
  • 是的,但型号名称始终为单数,控制器名称始终为复数,在您的情况下,型号名称为article.rb,控制器名称为articles_controller
  • 关注此 Rails 指南了解更多详情guides.rubyonrails.org/getting_started.html
  • 我正在尝试从 ui 制作文章
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多