我在导航器控制台中遇到 500 内部错误。
在服务器控制台中:
在 359 毫秒内完成 500 内部服务器错误
ActionView::MissingTemplate (Missing template questions/vote_for, application/vote_for with {:locale=>[:en], :formats=>[:js, :html], :handlers=>[:erb, :builder, :coffee]}. Searched in: * "/home/seif/Documents/ROR/Voting_trial/StackUnderflow/app/views" ):
app/controllers/questions_controller.rb:90:in `vote_for'Rendered /home/seif/.rvm/gems/ruby-2.0.0-p353/gems/actionpack-3.2.13/lib/action_dispatch/middleware/templates/rescues/missing_template.erb within rescues/layout (0.5ms)
问题是什么?
这是 vote_for 操作:
def vote_for
logger.info "***vote for***!!!"
logger.info params[:id]
@quest_vote_for = Question.find(params[:id])
current_user.vote_exclusively_for(@quest_vote_for)
respond_to do |format|
format.js
format.html
end
end
这是 View 调用:
<%=link_to raw( vote_for, vote_for_question_path(@question), :remote => true,:class =>"btn btn-default btn-lg" %>
最佳答案
更清楚地说...错误是因为找不到模板。
首先,如果您确实想支持 js 和 html 响应,那么您需要一个适用于两者的模板。
因此您需要以下其中一项:
/app/views/questions/vote_for.html.erb
/app/views/application/vote_for.html.erb (bad practice)
以及以下其中一项
/app/views/questions/vote_for.js.erb
/app/views/questions/vote_for.js.coffee
/app/views/application/vote_for.js.erb (bad practice)
/app/views/application/vote_for.js.coffee (bad practice)
关于javascript - Rails 500 服务器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21767193/