加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 在呈现简单的json头响应时获取“ActionView ::

发布时间:2020-12-17 03:02:37 所属栏目:百科 来源:网络整理
导读:在我的一个控制器中,我有这个代码: respond_to do |format| format.html{ redirect_to :me,:flash = {:error = t('quest_histories.misc.bad_request')}} and return format.json{ head :method_not_allowed } and returnend 但是,当json请求到来时,我收到
在我的一个控制器中,我有这个代码:

respond_to do |format|
  format.html{ redirect_to :me,:flash => {:error => t('quest_histories.misc.bad_request')}} and return
  format.json{ head :method_not_allowed } and return
end

但是,当json请求到来时,我收到此错误:

ActionView::MissingTemplate (Missing template quest_histories/index,application/index with {:locale=>[:en],:formats=>[:json],:handlers=>[:erb,:builder,:coffee]}. Searched in:
* "/var/www/PMAC_RoR/app/views"

这真让我感到困惑,因为我在许多其他控制器中都有类似的代码而且它实际上正在工作……控制器只需要用html头响应,它不需要模板.

解决方法

而不是“并返回”删除那些,并在整个respond_to块之后放回.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读