未定义的方法`article_name' ................. ArticlesController中的NoMethodError #create

时间:2016-02-27 13:47:27

标签: ruby-on-rails-3

class ArticlesController < ApplicationController
    def index
     @articles = Article.all
    end
    def show
     @article = Article.find(params[ :id])
    end
    def new
    @article = Article.new
    end
    def create
    @article = Article.new(article_params)
        if @article.save
    redirect_to @article
    else
     render 'new'
    end
    end

    private
     def article_params
           params.require(:article).permit(:Article_name,:enter_text)
    end
end

2 个答案:

答案 0 :(得分:1)

尝试:

..... .permit(:name, :enter_text)

答案 1 :(得分:0)

您需要省略类名,只需指定值名称。 请参阅下面的示例。

   private
     def article_params
           params.require(:article).permit(:name, :enter_text)
    end