Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error :The action 'show' could not be found for PostsController"

i have been learning rails through

http://guides.rubyonrails.org/getting_started.html.

I came across a error while performing save data in controller. The error that comes up when running the blog is :"The action 'show' could not be found for PostsController"

**

My code for posts_controller.rb is

**

class PostsController < ApplicationController
def new
end
def create
@post=Post.new(params[:post].permit(:title,:text))
@post.save
redirect_to @post
end

private
def post_params
params.require(:post).permit(:title,:text)
end

def show
@post=Post.find(params[:id])
end
end

**

My code for show.html.rb is

**

<p>
<strong> Title:</strong>
<%= @post.title %>
</p>
<p>
<strong> Text:</strong>
<%= @post.text %>
</p>

**

The code for create_posts.rb

**

class CreatePosts < ActiveRecord::Migration
  def change
    create_table :posts do |t|
      t.string :title
      t.text :text

      t.timestamps
    end
end

Please help me out why this error is coming up

like image 258
neha sharma Avatar asked Feb 16 '23 17:02

neha sharma


1 Answers

PostsController#show method should be public.

class PostsController < ApplicationController
  def new
  end

  def create
    @post=Post.new(params[:post].permit(:title,:text))
    @post.save
    redirect_to @post
  end

  def show
    @post=Post.find(params[:id])
  end

private

  def post_params
    params.require(:post).permit(:title,:text)
  end

end
like image 163
Marek Lipka Avatar answered Feb 18 '23 07:02

Marek Lipka