Forum: Ruby on Rails Problem with ruby on rails

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
D58c8b7dc5a826bfe778634eb7d21e11?d=identicon&s=25 hiram s. (hiram_s)
on 2013-07-29 20:15
I was working on this rails tutorial:
"http://guides.rubyon...ng_started.html" and than I got to the part that
you are supposed to show the title and data for an individual post (5.7)
and got an error when it was supposed to show the data, so I put
@post.inspect into /app/views/posts/show.html.erb and I got nil, and
same with the index page where it lists all of the posts, but I checked
and the data is in the database correctly.(in case this helps, on part
4.3 where you're supposed to uncomment # root to: "welcome#index", the
file said #root "welcome#index" instead, even though I'm using rails 4.0
and ruby 2.0) Here's my controller file:

class PostsController < ApplicationController
def new
def create
@post =, :text))
redirect_to @post
def post_params
params.require(:post).permit(:title, :text)
def show
@post = Post.find(params[:id])
def index
@posts = Post.all

here's the error:

NoMethodError in Posts#show
Showing /home/hiram/rails/meme/app/views/posts/show.html.erb where line
#3 raised:
undefined method `title' for nil:NilClass
Extracted source (around line #3):
1 <p>
2 <strong>Title:</strong>
3 <%= @post.title %>
4 </p>
6 <p>
Rails.root: /home/hiram/rails/meme
F50d3b02eee623a2172b58c09fe31c2c?d=identicon&s=25 mike (Guest)
on 2013-07-29 20:56
(Received via mailing list)
On Monday, July 29, 2013 2:15:38 PM UTC-4, User wrote:
> and ruby 2.0) Here's my controller file:
> def post_params
> here's the error:
> 5
> 6 <p>
> Rails.root: /home/hiram/rails/meme
> --
> Posted via

The following code:

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

must be at the end of the file.  Once you declare private, everything
defined after that will be considered private unless you change the
declaration.  The way you have this coded, the methods show and index
now be private and not available to the view.
This topic is locked and can not be replied to.