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

Couldn't find Article with 'id'=show

Bharat Mane
1#
Bharat Mane Published in 2018-02-05 07:36:05Z

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
Marek Lipka
2#
Marek Lipka Reply to 2018-02-05 08:40:11Z

Remove get 'articles/show' line from your routes.rb file.

You need to login account before you can post.

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

© 2016 Powered by mzan.com design MATCHINFO