NoMethodError on section 5.7 of Rails Guide

前端 未结 2 1700
萌比男神i
萌比男神i 2021-01-25 17:48

I\'m following the Getting Started tutorial for Rails 4.0.0 located here: http://guides.rubyonrails.org/getting_started.html

I\'m at the point in section 5.7 where I\'m

2条回答
  •  佛祖请我去吃肉
    2021-01-25 18:32

    I was having the same problem with the tutorial (which at this date (11/18/14) uses 'articles' instead of 'posts'), and found the solution to be the placement of the following "def" block in articles_controller.rb:

      def show
        @article = Article.find(params[:id])
        end
    

    Here's what it looks like for me:

    class ArticlesController < ApplicationController
    def new
        end
    
    def create
        @article = Article.new(article_params)
    
        @article.save
        redirect_to @article
    end
    
    def show
        @article = Article.find(params[:id])
    end
    
    private
    def article_params
        params.require(:article).permit(:title, :text)
    end 
    end
    

提交回复
热议问题