-1

error :

SQLite3::SQLException: no such column: articles.slug: SELECT "articles".* FROM "articles" WHERE "articles"."slug" = '33' ORDER BY "articles"."id" ASC LIMIT 1

code :

def show
  @article = Article.friendly.find(params[:id])
  @category = Category.find(@article.category_id)
  @comment = Comment.new
end
webster
  • 3,902
  • 6
  • 37
  • 59

1 Answers1

1

@article = Article.friendly.find(params[:id])

This will look for a slug column in the database’s articles table so you’ll need to create it and you’ll create a migration to do so.

$ rails g migration add_slug_to_articles slug:string

It’s a good idea to add an index for this attribute as it will be used for finding records.

class AddSlugToArticles < ActiveRecord::Migration
  def change
    add_column :articles, :slug, :string
    add_index :articles, :slug
  end
end

Run rake db:migrate now good to go

@article = Article.friendly.find(params[:id])
Anand
  • 6,457
  • 3
  • 12
  • 26
  • yes i did it even though it is displaying the id of the article in url insted of name of the article .....what to do? – Shivakumara m Nov 01 '17 at 14:13
  • @Shivakumara m can you tell me how are you coming to `show` action, i mean if you are using `link_to` what is that `url` which redirect it show action. please share `link_to .... ` – Anand Nov 01 '17 at 16:10
  • you should use like this example `<%= link_to 'Article', article_path(id: article.slug)%>` please cross check it if you are passing `article.slug` for `id` attribute – Anand Nov 01 '17 at 16:13