开发者

Why can't my controller test find a JS template?

In my Rails application I have a simple controller which also has an action with a JS view. During development mode I can access that view, but not during testing. During testing I get a "missing template" error.

I just can't figure out why this is happening. I'm posting the relevant parts, perhaps someone can help me with this.

routes.rb

resource :store, :controller => 'store' do    
  member do
    post :add_item
  end
end

store_controller_test

post :add_item, { :product_id => product.id }

Exception message

ActionView::MissingTemplate: Missing template store/add_item

Additional information:

  • The template file name is add_item.js.erb
  • Other views from the same controller work both in testing and develop开发者_Go百科ment.


The reason it can't find the template is because you are not creating a javascript post request in your tests, you are creating an HTML post request. To create a javascript post request, I would change the post call to specify the format.

post :add_item, { :product_id => product.id, :format => 'js' }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜