gpt4 book ai didi

ruby-on-rails - Rails 4 - 模板丢失

转载 作者:行者123 更新时间:2023-12-01 11:39:04 25 4
gpt4 key购买 nike

我希望你能帮我弄清楚为什么我会收到这个奇怪的错误。

我有以下表格:

index.html.erb

<%= 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 &rarr;
<% end %>
<% end %>

治疗 Controller .erb

 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

views/therapy/create.js.erb

<% if @result %>
alert("Success!");
<% else %>
alert("Fail!");
<% end %>

但是,当我提交表单时,出现以下错误:

Template is missing:

Missing template therapy/create, application/create with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder, :slim]}. Searched in: *...

知道为什么我会收到此错误吗?我不知道是什么原因造成的。

谢谢!

更新:

所以,我已经尝试了 MrYoshiji、Dave 和 Pavan 的建议,但我仍然遇到同样的错误。因此,在我的 therapy_controller.erb 中,我将其更改为:

respond_to do |format|
format.js
end

现在,我得到了错误:

ActionController::UnknownFormat in TherapyController#create 

有什么想法吗?

更新 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'

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

Source

关于ruby-on-rails - Rails 4 - 模板丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23569460/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com