title: "undefined method `title' for nil:NilClass" Rails Guides Tutorial
body: <p>I am working on RailsGuides Tutorial (creating a blog app). When I run server and open: <code>/posts/new</code> everything looks fine. But, when I try to create a post I get this error:</p>
  
  <blockquote>
    <p>NoMethodError in Posts#show</p>
    
    <p>Showing /home/darek/rails_projects/blog/app/views/posts/show.html.erb where line #3 
    raised:</p>
    
    <p>undefined method `title' for nil:NilClass</p>
  </blockquote>
  
  <p>Extracted source (around line #3):</p>
  
  <pre><code>1  &lt;p&gt;
  2  &lt;strong&gt;Title:&lt;/strong&gt;
  3  &lt;%= @post.title %&gt;
  4  &lt;/p&gt;
  5  &lt;p&gt;
  </code></pre>
  
  <p>In fact post is created, and I can see title and content at /posts
  But when I try to use show specific post I get this error. 
  My first clue was to change line </p>
  
  <pre><code>&lt;%= @post.title %&gt; 
  </code></pre>
  
  <p>to     </p>
  
  <pre><code>&lt;%= @post.try(:title) %&gt;
  </code></pre>
  
  <p>Error is gone, but problem isn't solved.<br>
  When I try to show specific post I get Title, and Text forms empty. It is not what I want to see ;)</p>
  
  <p>Ok, here is the code</p>
  
  <p>Show.html.erb</p>
  
  <pre><code>&lt;p&gt;
    &lt;strong&gt;Title:&lt;/strong&gt;
    &lt;%= @post.title %&gt;
  &lt;/p&gt;
  
  &lt;p&gt;
    &lt;strong&gt;Text:&lt;/strong&gt;
    &lt;%= @post.text %&gt;
  &lt;/p&gt;
  
  
  &lt;h2&gt;Add a comment:&lt;/h2&gt;
  &lt;%= form_for([@post, @post.comments.build]) do |f| %&gt;
    &lt;p&gt;
      &lt;%= f.label :commenter %&gt;&lt;br /&gt;
      &lt;%= f.text_field :commenter %&gt;
    &lt;/p&gt;
    &lt;p&gt;
      &lt;%= f.label :body %&gt;&lt;br /&gt;
      &lt;%= f.text_area :body %&gt;
    &lt;/p&gt;
    &lt;p&gt;
      &lt;%= f.submit %&gt;
    &lt;/p&gt;
   &lt;% end %&gt;
  
  &lt;%= link_to 'Edit Post', edit_post_path(@post) %&gt; |
  &lt;%= link_to 'Back to Posts', posts_path %&gt;
  </code></pre>
  
  <p>Posts_controller.rb</p>
  
  <pre><code>class PostsController &lt; ApplicationController
  
    def new 
      @post = Post.new
    end
  
    def index
      @posts = Post.all
    end
  
    def create
    @post = Post.new(params[:post].permit(:title, :text))
  
    if @post.save
    redirect_to @post
    else
      render 'new'
    end
  end
  
  private
    def post_params
     params.require(:post).permit(:title, :text)
    end
  
     def show
        @post = Post.find(params[:id])
     end
  
     def edit
        @post = Post.find(params[:id])
     end
  
      def update
        @post = Post.find(params[:id])
  
        if @post.update(params[:post].permit(:title, :text))
          redirect_to @post
        else 
          render 'edit'
        end
      end
  
      def destroy
        @post = Post.find(params[:id])
        @post.destroy
  
        redirect_to posts_path
      end
  end
  </code></pre>
  
  <p>Rake Routes:</p>
  
  <pre><code>-VirtualBox:~/rails_projects/blog$ rake routes
             Prefix Verb   URI Pattern                                 Controller#Action
      post_comments GET    /posts/:post_id/comments(.:format)          comments#index
                    POST   /posts/:post_id/comments(.:format)          comments#create
   new_post_comment GET    /posts/:post_id/comments/new(.:format)      comments#new
  edit_post_comment GET    /posts/:post_id/comments/:id/edit(.:format) comments#edit
       post_comment GET    /posts/:post_id/comments/:id(.:format)      comments#show
                    PATCH  /posts/:post_id/comments/:id(.:format)      comments#update
                    PUT    /posts/:post_id/comments/:id(.:format)      comments#update
                    DELETE /posts/:post_id/comments/:id(.:format)      comments#destroy
              posts GET    /posts(.:format)                            posts#index
                    POST   /posts(.:format)                            posts#create
           new_post GET    /posts/new(.:format)                        posts#new
          edit_post GET    /posts/:id/edit(.:format)                   posts#edit
               post GET    /posts/:id(.:format)                        posts#show
                    PATCH  /posts/:id(.:format)                        posts#update
                    PUT    /posts/:id(.:format)                        posts#update
                    DELETE /posts/:id(.:format)                        posts#destroy
               root GET    /                                           welcome#index
                    GET    /posts/:id(.:format)                        posts#view
                    DELETE /posts/:id(.:format)                        posts#destroy
  </code></pre>
  
  <p>Thanks for help and interest!</p>