带轨道的复杂订单语句AREL:SQL Case语句(Complex order statement with rails AREL: SQL Case statement)

我有一些基本上尝试在活动关系顺序方法中使用SQL case语句的代码:

relation = Foo.order("CASE WHEN foos.thing IS NOT NULL THEN 0 ELSE 1 END ASC")

并且在生成的(并执行的)SQL中它出现为:

(ORDER BY CASE ASC)

我已经尝试深入挖掘源代码并在visitor.access调用中丢失线程。 这是一个已知的问题? 是用户错误吗? 为了实现这个目标,我有什么神奇的事情要做吗? 我的印象是它只是插入了原始SQL。 我们正在对关系做其他事情,例如select,limit,offset,group,having和join。

帮帮我! :)


I've got this bit of code that basically tries to use a SQL case statement in the active relation order method:

relation = Foo.order("CASE WHEN foos.thing IS NOT NULL THEN 0 ELSE 1 END ASC")

and in the generated (and executed) SQL it comes up as:

(ORDER BY CASE ASC)

I've tried digging down into the source and lose the thread down in the visitor.access call. Is this a known issue? Is it user error? Is there some magical thing I have to do to make it happen? I was under the impression that it just inserted the raw SQL. There are other things we're doing with the relation, such as select, limit, offset, group, having and joins.

help! :)


原文:https://stackoverflow.com/questions/7810878
2024-01-07 17:01

满意答案

这些轨道剧的情节对我帮助很大。

  1. http://railscasts.com/episodes/279-understanding-the-asset-pipeline
  2. http://railscasts.com/episodes/282-upgrading-to-rails-3-1
  3. http://railscasts.com/episodes/318-upgrading-to-rails-3-2

摘要:

设置你的Gemfile

group :assets do
  gem 'sass-rails'
  gem 'coffee-rails'
  gem 'yui-compressor' # i'm using yui for compressor
end

将您的资产(javascripts,fonts,css,images等)移动到app / assets,我这样:

app/
  assets/
    fonts/
    images/
    javascripts/
    stylesheets/

并在css上,将url帮助器更改为font-url,image-url或assets-url。 您可以在此处找到更多信息, https://github.com/rails/sass-rails 。 也许您会想要使用登台服务器检查资产管道工作是否正常,至少对于您的应用服务的静态资产。 还要确保加载了多次javascript文件。 (当我升级到资产管道时,它让我头疼)。

希望这个帮助。


These episodes of railscasts helped me a lot.

  1. http://railscasts.com/episodes/279-understanding-the-asset-pipeline
  2. http://railscasts.com/episodes/282-upgrading-to-rails-3-1
  3. http://railscasts.com/episodes/318-upgrading-to-rails-3-2

The summary:

Set your Gemfile

group :assets do
  gem 'sass-rails'
  gem 'coffee-rails'
  gem 'yui-compressor' # i'm using yui for compressor
end

move your assets (javascripts, fonts, css, images, etc) to app/assets, mine like this:

app/
  assets/
    fonts/
    images/
    javascripts/
    stylesheets/

and on the css, change the url helper to something like font-url, image-url, or assets-url. You can find more information here, https://github.com/rails/sass-rails. Maybe you will want to use a staging server to check if the assets pipelining working fine, at least for the static assets your app serve. Also to make sure there's javascript file loaded more than once. (It gave me a headache before when I upgrading to assets pipeline).

hope this help.

相关问答

更多

升级到Rails 3.1后找不到图片资产(Image assets not found after upgrading to Rails 3.1)

资产管道指南中未提及的最大的一件事是删除前导/图像/部分路径。 举个例子: <%= image_tag "/images/about/header.png" %> 必须更改为: <%= image_tag "about/header.png" %> CSS文件也一样。 所以这: background-image: url("/images/alliance/header_background.png"); 将改为: background-image: image-url("alliance/...

使用capistrano从rails 3升级到rails 4,现在图像资产没有显示。(Upgrade from rails 3 to rails 4 with capistrano, now image assets are not showing. Why?)

Rails 4不再创建没有摘要的资产。 因此,如果您在URL中没有摘要的情况下直接引用资源(例如图像)(例如/assets/whatever.jpg ),您可能会获得404。 non-stupid-digest-assets gem将通过创建非消化资产来解决这个问题: https : //github.com/alexspeller/non-stupid-digest-assets/tree/master This is all my bad...I haven't been using the ...

rails资产管道产生了javascript(rails assets pipeline with yielded javascript)

需要预编译HTML头部分中所需的每个JS文件。 默认情况下,只预编译application.js,但您可以在config / application.rb中安排其他文件进行预编译: config.assets.precompile += ['admin.js', 'customer_page.js'] 如果要将JS文件组合在一起,那些文件可以是清单,就像application.js一样。 Every JS file that is being required in the HTML head ...

Rails 3.1,资产管道:没有路由匹配(Rails 3.1, asset pipeline: no route matches)

如果您预编译资产并将compile设置为false,则禁用调试,因为您已经告诉Rails根本不使用Sprockets,但是假设nginx可以根据资产管道清单中的映射来提供文件。 如果编译为真(就像你一样),那么对这些资产(和调试请求)的请求将被发送回Sprockets,以便在文件丢失时进行处理(未经过预编译就是这种情况)。 我原以为Sprockets会为每个被消化的名称提供单独的文件。 这种行为对我来说听起来很麻烦,尽管我认为无论如何都不打算在生产中使用调试。 If you precompile ...

Rails 3.1资产管道:更改默认URL(/ assets)(Rails 3.1 asset pipeline: change default URL (/assets))

在config / application.rb中 ,下面 config.assets.enabled = true 你可以加 : config.assets.prefix = "static" 而已 :) In config/application.rb, below config.assets.enabled = true you can add : config.assets.prefix = "static" That's it :)

Rails 3.1资产管道没有缩小(Rails 3.1 asset pipeline is not minifying)

使用此命令: rake RAILS_ENV=production RAILS_GROUP=assets assets:precompile This solved my problem.... http://groups.google.com/group/rubyonrails-core/browse_thread/thread/4bc7bac8b295b3aa

如何让Rails 3.1使用新的Assets Pipeline?(How do I get Rails 3.1 to use the new Assets Pipeline?)

你应该有application而不是:defaults : <%= stylesheet_link_tag "application" %> <%= javascript_include_tag "application" %> 然后确保您的app/assets/stylesheets/application.css和app/assets/javascripts/application.js在顶部有相应的清单指令。 You should have application instead of :...

逐步升级到Rails资产管道(Incrementally upgrading to Rails assets pipeline)

这些轨道剧的情节对我帮助很大。 http://railscasts.com/episodes/279-understanding-the-asset-pipeline http://railscasts.com/episodes/282-upgrading-to-rails-3-1 http://railscasts.com/episodes/318-upgrading-to-rails-3-2 摘要: 设置你的Gemfile group :assets do gem 'sass-rails'...

Rails升级到bootstrap 4(Rails upgrading to bootstrap 4)

Bootstrap Sprockets提供单独的Bootstrap组件,以便于调试。 再次阅读bootstrap-rubygem中的说明 ,你会发现没有假设是bootstrap-sprockets的导入。 // app/assets/stylesheets/application.scss @import "bootstrap-sprockets"; // Remove this line 然而,假设它是一个javascript需要它。 这可以替换为仅用于引导的需求,以便更快地进行编译(您目前正在...

Rails 3.1资产管道无法正常工作(Rails 3.1 asset pipeline not working)

似乎红宝石版本是我的问题,我降级为红宝石1.9.3,然后重新安装宝石,它现在工作! It seems the ruby version was my problem, I downgraded to ruby 1.9.3, then reinstalled gems and it works now!

相关文章

更多

JDBC系列教程之四:SQL注入PreparedStatement和Statement

在SQL中包含特殊字符或SQL的关键字(如:' or 1 or ')时Statement将出现不可预料 ...

sql问题

有表格如下: t_table 8 想得到这样的结果:(只取有重复的第一个,相同的排除,例如f) 1 a ...

问一条sql语句

我要查询所有记录,并且要让state=2的记录排在前面,我该怎么样表达?谢谢 问题补充: stat ...

sql 语句

每天24小时,现在数据表里只有7,8,9点有数据 怎么得到24条数据?? 其他的没数据的时间都是0 ...

如何优化这个sql语句

SELECT a.type, b.postnature, b.compcode FROM 职工岗位管 ...

《JAVA代码规范》(六)通用代码格式 - 语句、SQL(2.9-2.10)

简单语句:每行至多包含一条语句;复合语句:复合语句是包含在大括号中的语句序列,形如"{ 语句 }";返 ...

不会sql语句....谁帮我优化下

select * from dbo.tbGoodsInfo where (id in (select ...

sql语句-关于行列互换等问题的查询语句

1.表结构如下: 1991 1.1 21 1991 1.2 22 1991 1.3 23 19 ...

SQL Server 压力测试

转自:http://www.cnblogs.com/Amaranthus/archive/2011/0 ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本