我有表彰/ _create.html.erb,其中包含表格 -
<%= form_for(current_user.commendations.new(...), remote: true) do |f| %>
<%=...
和commendations_controller.rb
def create
...
respond_to do |format|
format.html { redirect_to :back }
format.js
end
end
但我在服务器日志中收到以下错误 -
Completed 500 Internal Server Error in 7ms
ActionView::MissingTemplate (Missing template commendations/create, application/create with {:locale=>[:en], :formats=>[:js, :html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}. Searched in:
* "/Users/dan/Documents/ROR/fic/app/views"
* "/Users/dan/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/devise-3.4.1/app/views"):
app/controllers/commendations_controller.rb:9:in `create'
我无法看到我出错的地方 - remote: true
应该触发format.js
,而 resources :commendations, only: [:create]
应该重新加载部分,不是吗?
在routes.rb中我有
{{1}}
答案 0 :(得分:2)
您需要在app / views / commendations /
中使用名为create.js的文件在create.js中执行:
$("#your_div").html( "<%= j render( :partial => 'commendations/your_partial') %>" );