Dod*_*nas 3 ajax ruby-on-rails missing-template
我希望你能帮助我弄清楚为什么我会得到这个特殊的错误.
我有以下表格:
<%= form_for :response, :url => {:action => 'create'}, :remote => true do |f| %>
<%= f.hidden_field :template_id, :value => @template.id %>
<%= button_tag(type: 'submit', class: "btn btn-primary btn-lg pull-right next-slide") do %>
Next →
<% end %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
def create
@response = Response.new(response_params)
respond_to do |format|
if @result = @response.save
format.html
format.js
else
format.html { render :action => "new" }
format.js
end
end
end
Run Code Online (Sandbox Code Playgroud)
<% if @result %>
alert("Success!");
<% else %>
alert("Fail!");
<% end %>
Run Code Online (Sandbox Code Playgroud)
但是,当我提交表单时,我收到以下错误:
模板丢失:
缺少模板疗法/创建,应用/创建{:locale => [:en],:formats => [:html] ,:handlers => [:erb,:builder,:raw,:ruby,:coffee,: jbuilder,:slim]}.搜索:*...
任何想法为什么我会得到这个错误?我无法弄清楚是什么导致了它.
谢谢!
所以,我已经尝试过Yoshiji先生,Dave先生和Pavan先生的建议,但我仍然得到同样的错误.所以,在我therapy_controller.erb,我已经改为:
respond_to do |format|
format.js
end
Run Code Online (Sandbox Code Playgroud)
现在,我收到错误:
ActionController::UnknownFormat in TherapyController#create
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
更新2:以下是服务器日志:
Started POST "/therapy" for 152.79.45.121 at 2014-05-15 18:01:21 +0000
Processing by TherapyController#create as HTML
Parameters: {"utf8"=>"?", "response"=>{"template_id"=>"2"}, "commit"=>"Save Response"}
Completed 406 Not Acceptable in 1ms
ActionController::UnknownFormat (ActionController::UnknownFormat):
app/controllers/therapy_controller.rb:13:in `create'
Run Code Online (Sandbox Code Playgroud)
而routes.rb文件是在这里: https://gist.github.com/dodinas/fb0a39282022e961ce09
谢谢.
试试这个
def create
@response = Response.new(response_params)
respond_to do |format|
if @result = @response.save
format.html
format.js { render 'create.js.erb' }
else
format.html { render :action => "new" }
format.js
end
end
end
Run Code Online (Sandbox Code Playgroud)