2016-03-25 7 views
1

チュートリアルをオンラインで試してみると、 '間違った引数の数(2の1)'というエラーが表示されます。私はRailsに全く慣れていないだけで、ガイドを辿ってみようとしています。引数が間違っています(2の場合1) - Rails - 強いパラメータかもしれません

するコントローラである。

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

def new 

end 

def create 
    @article = Article.new(article_params) 

    @article.save 
    redirect_to @article 
end 

private 
    def article_params 
     params.require(:article).permit(:title, :text) 
    end 

end 

マイデータベース・コードは:所与

class CreateArticles < ActiveRecord::Migration 
    def change 
    create_table :articles do |t| 
    t.string :title 
    t.text :text 

    t.timestamps null: false 
    end 
    end 
end 

パラメータは、

{"utf8"=>"✓", "authenticity_token"=>"JfpQBSnxU8O839o5YjbZV11TMAWTPgaok1/skSEoGlchdGCulmJuGxFdyj7lUK6WIfrLddCZAaWxOkxRaNqlTA==", 
"article"=>{"title"=>"hello world", 
"text"=>"hello olivia"}, 
"commit"=>"Save Article"} 

任意の助けを大幅に高く評価される:)

+0

どうぞよろしくお願いします。 –

+0

ねえはいそれは ArticlesControllerのArgumentError#create – OEThorne

+0

エラーのスタックトレースをお願いしますか? – archana

答えて

0

このコードを試してみると、コンソールにエラーが表示されますか?

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

    def new 

    end 

    def create 
     @article = Article.new(article_params) 

     if @article.save 
      redirect_to article_path(@article) 
     else 
      logger.warn(@article.errors) 
      render "new" 
     end 
    end 

    private 
     def article_params 
      params.require(:article).permit(:title, :text) 
     end 

    end 
+0

新しいエラーはコンソールに表示されません。 – OEThorne

+0

[pry](https://github.com/rweng/pry-rails)やbyebugを使ってみましたか? – Louis

0

ifブロックで@ article.saveを呼び出さないために問題が発生している可能性があります。あなたは@ article.saveを呼び出してから、リダイレクトを呼び出します。試してみてください:

if @article.save 
    redirect_to @article 
else 
    render :new 
end 
+0

これを試しましたが、依然として同じ内部サーバーエラーが発生しています。 – OEThorne

+0

実際のエラーを表示できますか? – hashrocket

+0

また、新しいメソッドに@article = Article.newを追加してみてください。 – hashrocket

関連する問題