私は自分のアプリケーションに問題があります。私は今あなたにアプリケーションのコードを渡します。エラーの画像です。これは私の仕事です。 Ruby on RailsからWebアプリケーションを作成するには、記事を作成してデータベースに保存する必要があります。ArticlesControllerのNoMethodErrorは、nilのための未定義メソッドsaveを作成します。NilClass
これは誤差の画像です:https://i.stack.imgur.com/hYTkl.png
私の雲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'
article.rb:
class Article < ActiveRecord::Base
end
articles_controller.rb :
class ArticlesController < ApplicationController
def new
@article = Article.new
end
def create
#render plain: params[:article].inspect
@article.save
redirect_to_articles_show(@article)
end
private
def article_params
params.require(:article).permit(:title, :description)
end
end
new.html.erb:
class CreateArticles < ActiveRecord::Migration
def change
create_table :articles do |t|
t.string :title
t.text :description
end
end
end
私のschema.rb:
ActiveRecord::Schema.define(version: 20170820190312) do
create_table "articles", force: :cascade do |t|
t.string "title"
t.text "description"
end
end