2

我收到以下错误:

ActionView::MissingTemplate (Missing template product/create, application/create with {:locale=>[:en], :formats=>[:js, :html], :handlers=>[:erb, :builder, :haml]}

控制器代码:

  def create
    product = Product.new(params[:product])
    product.save
  end

我得到这个的原因是因为我没有针对此操作或模板文件的 respond_to 块。这是我通过 AJAX 运行以创建product. 将其发送到服务器后,我不需要/不想回复任何内容。有没有办法禁用它,所以我不会收到这些错误?我能想到的最好的方法是创建一个respond_toformat.js并创建一个_create.js.erb空白但看起来像黑客的文件。

谢谢

4

1 回答 1

3

只需添加

render nothing: true

http://guides.rubyonrails.org/layouts_and_rendering.html#rendering-nothing

于 2012-11-23T06:58:55.910 回答