【发布时间】:2017-08-21 15:25:07
【问题描述】:
我的 ruby on rails cloud 9 代码有问题,而我的任务是从 UI 创建一篇文章并在我点击提交时将其保存到数据库中。
这是我的问题的图像:
这是我的 cloud 9 代码
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'
resources :articles
root 'pages#home'
get 'about', to: 'pages#about'
end
文章控制器 (articles_controller.rb):
class ArticlesController < ApplicationController
def new
@article = Article.new
end
end
视图中文章文件夹中的new.html.erb:
<h1>Create an article</h1>
<%= form_for @article do |f| %>
<p>
<%= f.label :title %>
<%= f.text_area :title %>
</p>
<% end %>
文章模型(article.rb):
class Article < ActiveRecord::Base
end
我已经完成了迁移,这是我的迁移文件:
class CreateArticles < ActiveRecord::Migration
def change
@article = Article.new
create_table :articles do |t|
t.string :title
end
end
end
【问题讨论】:
-
您的迁移文件中的数据有误。我建议你阅读guides.rubyonrails.org/getting_started.html
-
这里的缩进实际上是不存在的,这确实损害了可读性。在提出问题时,请努力使您的代码尽可能干净和美观。让其他人难以理解正在发生的事情是不好的。
-
我很抱歉我是堆栈溢出的新手,我不打算让人们挣扎,我已经改变并尽力从我的代码中复制它
标签: ruby-on-rails ruby ruby-on-rails-4 nomethoderror cloud9