Railsのお部屋

忘備録

Missing template

Rspecでテストコード書いてたときにはまってたとこ。

post :create , word: params[:hogehoge]

こんな風にpostでcreate actionにとばしていたのですが、 createのtemplateがない!ということでずっと下のエラーが出ていました。

RSpec::Rails::ViewRendering::EmptyTemplatePathSetDecorator ActionView::TemplateError (Missing template)

indexのtemplateしかありません。

controllerに render :nothing => true と書くことで回避できます。 指定しないと、対応するtemplateを探しにいってしまってエラーが出るようです。

ただし、ajaxを使用している場合のpostの書き方はこっち xhr :post, :create, word: params[:hogehoge]