【问题标题】:Why is my Rails App Processing as JS and */*为什么我的 Rails 应用程序处理为 JS 和 */*
【发布时间】:2016-02-17 05:17:01
【问题描述】:

我最近在查看我的 Rails 4 应用程序的日志,发现它正在将 show 操作作为 JavaScript 和 */* 处理。

Processing by ArticlesController#show as */*

Processing by ArticlesController#show as JS

我很难弄清楚这意味着什么。这值得关注吗?我认为它应该只作为 HTML 处理。

这是我的节目:

def show
    @article = Article.find(params[:id])
    @related = Article.where.not(id: @article.id).tagged_with(@article.tag_list, :any => true).take(4)
    @most_popular = Article.where.not(id: @article.id).order(impressions_count: :desc).take(50).sample(8)
    @feedback = @article.feedbacks.build
    impressionist(@article, :unique => [:session_hash])
    @articles = Article.where.not(id: @article.id).order(updated_at: :desc).paginate(page: params[:page]).per_page(12)
end

【问题讨论】:

  • 如何从浏览器中点击显示操作?
  • www.mysite.com/articles/:id -- 这是我的网站@Arup 上各种文章的显示页面
  • @Kathan 你解决了吗?

标签: ruby-on-rails ruby-on-rails-4 controller


【解决方案1】:

您实际上可以通过在您的操作中添加一个 respond_to 块来设置操作的响应类型更多信息here

在你的表演动作的最后加上这个,让我知道它是否按预期工作,谢谢。

respond_to do |format|
  format.html
end

【讨论】:

  • 当该块没有到位时,它如何确定选择哪种响应类型? @sghosh
  • 他们是请求头中的这个字段 Content-Type ,我猜你可以使用 request.format 或 request.content_type 在控制器中检查它
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-29
  • 1970-01-01
  • 1970-01-01
  • 2017-01-19
  • 2011-05-06
  • 2020-07-18
相关资源
最近更新 更多