0

如果没有需要remote form的response怎么处理呢?

错误是

ActionView::MissingTemplate (Missing template carts/search_book_by_sn, application/search_book_by_sn with {:locale=>[:en], :formats=>[:js, :html], :handlers=>[:erb, :builder, :coffee, :haml]}. Searched in:

我的控制器中的代码。因为

如果 session[:loaded_books].include? @book.id

是错误结果的条件,所以我不想执行任何 Javascript。只要保持与原产地相同

respond_to do |format|
  # format.js

  if session[:loaded_books].include? @book.id
    format.js
  else
    ap("Add into Array")
    session[:loaded_books] << @book.id
    ap(session[:loaded_books])

    format.js { render :action => 'add_to_cart'}

  end

end

提前致谢

4

3 回答 3

7

如果您不想发送任何响应或呈现任何视图,那么写入操作

render :nothing => true
于 2013-10-23T11:05:45.497 回答
1
respond_to do |format|
  # format.js

  if session[:loaded_books].include? @book.id
    format.js {render :nothing => true } # this might help
  else
    ap("Add into Array")
    session[:loaded_books] << @book.id
    ap(session[:loaded_books])

    format.js { render :action => 'add_to_cart'}

  end

end
于 2013-10-23T11:07:51.517 回答
1

只需在控制器中执行 render :nothing => true

于 2013-10-23T11:44:15.347 回答