小编Yan*_*nis的帖子

Rails3使用text/html内容类型而不是text/javascript呈现js.erb模板

我正在使用3.0.0.beta3构建一个新的应用程序.我只是尝试将js.erb模板呈现给Ajax请求以执行以下操作(在publications_controller.rb中):

def get_pubmed_data
    entry = Bio::PubMed.query(params[:pmid])# searches PubMed and get entry
    @publication = Bio::MEDLINE.new(entry) # creates Bio::MEDLINE object from entry text
    flash[:warning] = "No publication found."if @publication.title.blank? and @publication.authors.blank? and @publication.journal.blank?      
    respond_to do |format|
        format.js
    end
end
Run Code Online (Sandbox Code Playgroud)

目前,我的get_pubmed_data.js.erb模板很简单

alert('<%= @publication.title %>')
Run Code Online (Sandbox Code Playgroud)

服务器正在响应以下内容

alert('Evidence for a herpes simplex virus-specific factor controlling the transcription of deoxypyrimidine kinase.')
Run Code Online (Sandbox Code Playgroud)

不同之处在于没有在浏览器中发生的,可能是因为内容类型的响应是不是如图这里部分转载响应头"文/ JavaScript的""text/html的",这是完美的罚款:

Status 200
Keep-Alive timeout=5, max=100
Connection Keep-Alive
Transfer-Encoding chunked
Content-Type text/html; charset=utf-8
Run Code Online (Sandbox Code Playgroud)

这是一个错误还是我错过了什么?谢谢你的帮助!

javascript ajax content-type ruby-on-rails-3

8
推荐指数
1
解决办法
1万
查看次数

Rails 5.2和webpacker 3.4.3:部署到Heroku时未编译的资产

我刚刚将我的Rails应用程序从5.1.6升级到5.2,并抓住机会将Webpacker从2.0升级到3.4.3.

现在,当我将应用程序推送到Heroku时,我收到以下错误(vendor.js是我的application.html.erb模板中的文件/app/javascript/packs和他所调用的文件之一javascript_pack_tag 'vendor'):

ActionView::Template::Error (Webpacker can't find vendor.js in /app/public/packs/manifest.json. Possible causes: 
1. You want to set webpacker.yml value of compile to true for your environment 
   unless you are using the `webpack -w` or the webpack-dev-server. 
2. webpack has not yet re-run to reflect updates. 
3. You have misconfigured Webpacker's config/webpacker.yml file. 
4. Your webpack configuration is not creating a manifest. 
Your manifest contains: 
{ 
} 
):
Run Code Online (Sandbox Code Playgroud)

事实上,当我检查内容时,/public我可以看到/packs应该包含我的资产的目录丢失了.

我可以看到,在Heroku的构建阶段,资产是预编译的:

Running: rake assets:precompile …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails heroku webpack webpacker

6
推荐指数
1
解决办法
1355
查看次数

ActiveRecord查询:按所包含模型的总和排序

  • 项目has_many:项目
  • 项目belongs_to:项目

我正在尝试按各自项目的总价格对项目进行排序.就像是:

Project.includes(:items).order('SUM(items.price)')
Run Code Online (Sandbox Code Playgroud)

使用此代码,ActiveRecord仅返回第一个项目.我错过了什么?

mysql activerecord ruby-on-rails ruby-on-rails-3

4
推荐指数
1
解决办法
2144
查看次数