Home Couldn't find Article with 'id'=show
Reply: 0

Couldn't find Article with 'id'=show

user10401
1#
user10401 Published in September 20, 2018, 12:56 pm

I know this question may be simple and related to other problems but in my case those solutions are not working, so my question is how to deal with this problem?

While I try to show the article I am getting this error:

ActiveRecord::RecordNotFound in ArticlesController#show couldn't find article with 'id'=show

I am stucking here

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

Here is my code snippets My article_controller.rb look like this

class ArticlesController < ApplicationController
  def index
    @articles= Article.all
  end

  def show
    @article = Article.find(params[:id])
  end

  def new
    @article= current_user.articles.build
  end

  def create
    @article=current_user.articles.build(@article_params)
    if @article.save
      redirect_to articles_path
    else
      render 'new'
    end
  end

  def edit
    @article=Article.new(article_params)
  end 
end

my index.html.erb looks like this

<h2>welcome index</h2>

<ul>
  <% @articles.each do |article| %>
    <%= article.titile %>
    <%= article.body %>
  <% end %>
</ul>

my show.html.erb look like this

<h2><%= @article.title %></h2>
<p><%= @article.body %></p>

my Routes look like this

Rails.application.routes.draw do
  devise_for :users

  root 'articles#index'

  resources :articles

  get 'articles/show'
end
share|improve this question
  • Have you created an article with id = params[:id]? – Sakshi Jain Feb 5 at 7:39
  • How does the link to the article look like? – Marek Lipka Feb 5 at 7:41
  • this is the next show.html.erb part <% @articles.each do |article| %> <li> <%= link_to article.title, article_path(article), class: 'article_title', id: "article_#{article.id}" %> </li> <% end %> and my routes look like this root 'articles#index' resources :articles – Bharat Mane Feb 5 at 8:11
  • @BharatMane please show your config/routes.rb file and the link you're trying to open in browser – nattfodd Feb 5 at 8:23
  • @BharatMane add this information to the question by editing it. And, as nattfodd wrote, include your config/routes.rb content. – Marek Lipka Feb 5 at 8:30

1 Answer 1

active oldest votes
up vote 1 down vote accepted
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.504955 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO