0

I'm have article table

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

    t.timestamps
  end
end

end

followed friendly_id README

1). rails generate friendly_id

2.) add extend to Article model

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

3). add slug field to article table

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

open web browser http://localhost:3000/article/new could see rails terminal

enter image description here this is issue place in article controller:

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

this terminal error report:

enter image description here

F___
  • 149
  • 3
  • 17

1 Answers1

0

ye, found this error, because not add parameter on strong params

 def article_params
   params.require(:article).permit(:title, :body, :catalog_id, :slug)
 end
F___
  • 149
  • 3
  • 17