title: New to Ruby on Rails - Association Issue
body: <p>I am trying to set the associations . By now I have both models Post and Comment with their associations (in theory).</p>
  
  <p>The problem is that when I try to see the comment of a specific post it says that such method does not exist.</p>
  
  <p>I am sure  forgetting something kinda obvious but I can't figure it out.
  Thanks in advance!</p>
  
  <p>MODELS </p>
  
  <pre><code>class Post &lt; ActiveRecord::Base
    has_many :comments, dependent: :destroy
  end
  
  class Comment &lt; ActiveRecord::Base
    belongs_to :post
  end
  </code></pre>
  
  <p>And i got the error on rails console:</p>
  
  <pre><code>p = Post.all
  
  p[0].comments
  
  "undefined method comments for post"
  </code></pre>
  
  <p>Controllers:</p>
  
  <p>Coment:</p>
  
  <pre><code>class CommentsController &lt; ApplicationController
    before_action :set_comment, only: [:show, :edit, :update, :destroy]
  
    # GET /comments
    # GET /comments.json
    def index
      @comments = Comment.all
    end
  
    # GET /comments/1
    # GET /comments/1.json
    def show
    end
  
    # GET /comments/new
    def new
      @comment = Comment.new
    end
  
    # GET /comments/1/edit
    def edit
    end
  
    # POST /comments
    # POST /comments.json
    def create
      @comment = Comment.new(comment_params)
  
      respond_to do |format|
        if @comment.save
          format.html { redirect_to @comment, notice: 'Comment was successfully created.' }
          format.json { render action: 'show', status: :created, location: @comment }
        else
          format.html { render action: 'new' }
          format.json { render json: @comment.errors, status: :unprocessable_entity }
        end
      end
    end
  
    # PATCH/PUT /comments/1
    # PATCH/PUT /comments/1.json
    def update
      respond_to do |format|
        if @comment.update(comment_params)
          format.html { redirect_to @comment, notice: 'Comment was successfully updated.' }
          format.json { head :no_content }
        else
          format.html { render action: 'edit' }
          format.json { render json: @comment.errors, status: :unprocessable_entity }
        end
      end
    end
  
    # DELETE /comments/1
    # DELETE /comments/1.json
    def destroy
      @comment.destroy
      respond_to do |format|
        format.html { redirect_to comments_url }
        format.json { head :no_content }
      end
    end
  
    private
      # Use callbacks to share common setup or constraints between actions.
      def set_comment
        @comment = Comment.find(params[:id])
      end
  
      # Never trust parameters from the scary internet, only allow the white list through.
      def comment_params
        params.require(:comment).permit(:post_id, :body)
      end
  end
  </code></pre>
  
  <p>Post: </p>
  
  <pre><code>class PostsController &lt; ApplicationController
    before_action :set_post, only: [:show, :edit, :update, :destroy]
  
    # GET /posts
    # GET /posts.json
    def index
      @posts = Post.all
    end
  
    # GET /posts/1
    # GET /posts/1.json
    def show
    end
  
    # GET /posts/new
    def new
      @post = Post.new
    end
  
    # GET /posts/1/edit
    def edit
    end
  
    # POST /posts
    # POST /posts.json
    def create
      @post = Post.new(post_params)
  
      respond_to do |format|
        if @post.save
          format.html { redirect_to @post, notice: 'Post was successfully created.' }
          format.json { render action: 'show', status: :created, location: @post }
        else
          format.html { render action: 'new' }
          format.json { render json: @post.errors, status: :unprocessable_entity }
        end
      end
    end
  
    # PATCH/PUT /posts/1
    # PATCH/PUT /posts/1.json
    def update
      respond_to do |format|
        if @post.update(post_params)
          format.html { redirect_to @post, notice: 'Post was successfully updated.' }
          format.json { head :no_content }
        else
          format.html { render action: 'edit' }
          format.json { render json: @post.errors, status: :unprocessable_entity }
        end
      end
    end
  
    # DELETE /posts/1
    # DELETE /posts/1.json
    def destroy
      @post.destroy
      respond_to do |format|
        format.html { redirect_to posts_url }
        format.json { head :no_content }
      end
    end
  
    private
      # Use callbacks to share common setup or constraints between actions.
      def set_post
        @post = Post.find(params[:id])
      end
  
      # Never trust parameters from the scary internet, only allow the white list through.
      def post_params
        params.require(:post).permit(:title, :body)
      end
  end
  </code></pre>