title: Ruby on Rails NoMethodError in Posts#show
body: <p>I have been attempting to write a web blog application based off this <a href="http://railsinstallfest.org/guides/installfest4/getting_started/" rel="nofollow">link</a>. I am getting a 
  Ruby on Rails NoMethodError in Posts#show error when I got to click on a post. </p>
  
  <p>The error states: <code>"undefined method post_comments_path"</code> on the line: <code>&lt;%= form_for [@post, Comment.new] do |f| %&gt;</code></p>
  
  <p>This is in my app/views/posts/show.html.erb script. This script is as follows:</p>
  
  <pre><code> &lt;p id="notice"&gt;&lt;%= notice %&gt;&lt;/p&gt;
  
   &lt;%= render :partial =&gt; @post %&gt;
  
   &lt;%= link_to 'Edit', edit_post_path(@post) %&gt; |
   &lt;%= link_to 'Back', posts_path %&gt;
  
   &lt;h2&gt;Comments&lt;/h2&gt;
   &lt;div id="comments"&gt;
    &lt;%= render :partial =&gt; @post.comments %&gt;
   &lt;/div&gt;
  
  &lt;%= form_for [@post, Comment.new] do |f| %&gt;
    &lt;p&gt;
      &lt;%= f.label :body, "New comment" %&gt;&lt;br/&gt;
      &lt;%= f.text_area :body %&gt;
    &lt;/p&gt;
    &lt;p&gt;&lt;%= f.submit "Add comment" %&gt;&lt;/p&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>With the partial: </p>
  
  <pre><code>&lt;%= div_for comment do %&gt;
    &lt;p&gt;
      &lt;strong&gt;
        Posted &lt;%= time_ago_in_words(comment.created_at) %&gt; ago
      &lt;/strong&gt;
      &lt;br/&gt;
      &lt;%= comment.body %&gt;
    &lt;/p&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>I believe though the issue may be in my routes.rb file. The tutorial states to have:</p>
  
  <pre><code>QuickBlog::Application.routes.draw do
    resources :posts do
      resources :comments, :only =&gt; [:create]
    end
  
    # root :to =&gt; 'welcome#index'
  end
  </code></pre>
  
  <p>but I could not get my server to load with this configuration. Instead my routes file is:</p>
  
  <pre><code>Rails.application.routes.draw do
    resources :comments
    resources :posts
  
    devise_for :users
    root "pages#home"
    get "about" =&gt; "pages#about"
  end
  </code></pre>
  
  <p>Any help on how to fix this would be greatly appreciated as I have not found another page with a similar issue with relation to the error.</p>
  
  <p>When I update my routes.rb file to be the same as the tutorial it is as follows:</p>
  
  <pre><code>QuickBlog::Application.routes.draw do
    resources :posts do
      resources :comments, :only =&gt; [:create]
    end
  
    # root :to =&gt; 'welcome#index'
  
    devise_for :users
    root "pages#home"
    get "about" =&gt; "pages#about"
  end
  </code></pre>
  
  <p>I the receive the error in the terminal:</p>
  
  <pre><code>routes.rb:1:in `&lt;top (required)&gt;': uninitialized constant QuickBlog (NameError)
  </code></pre>
  
  <p>My comments controller is:</p>
  
  <pre><code>class CommentsController &lt; ApplicationController
    def create
      @post = Post.find(params[:post_id])
      @comment = @post.comments.create!(comment_params)
      redirect_to @post
    end
  
    private
  
    def comment_params
      params.require(:comment).permit(:body)
    end
  end
  </code></pre>