2017-12-02 3 views
0

私はarticleテーブルfriendly-idにはテーブルにslugカラムが追加されていますが見つかりませんでしたか?

class CreateArticles < ActiveRecord::Migration[5.1] 
def change 
    create_table :articles do |t| 
    t.string :title 
    t.text :body 

    t.timestamps 
    end 
end 

エンド

は)

READMEに従ってきています。 rails generate friendly_id

2.)Articleモデル

class Article < ApplicationRecord 
    extend FriendlyId 
    friendly_id :title, use: :slugged' 
end 

3)まで延び加えます。

def show 
    @article = Article.friendly.find(params[:id]) 
    @comments = @article.comments.order("created_at desc").paginate(:page => params[:page], per_page: 4) 

    respond_to do |format| 
    format.html 
    format.json { render json: [@article, @comments], except: [:created_at, :updated_at] } 
    end 
end 

この端末エラーレポート:

enter image description here

class AddSlugToArticle < ActiveRecord::Migration[5.1] 
    def change 
    add_column :articles, :slug, :string 
    add_index :articles, :slug, unique: true 
    end 
end 

オープンWebブラウザhttp://localhost:3000/article/newrails terminal

enter image description here この記事のコントローラにおける問題の場所であると見ることができる追加

答えて

0

あなたがたは、このエラーが見つかった、強いのparamsにパラメータを追加していないので、

def article_params 
    params.require(:article).permit(:title, :body, :catalog_id, :slug) 
end 
関連する問題