带轨道的复杂订单语句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
满意答案
这些轨道剧的情节对我帮助很大。
- 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' 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.
- 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
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)
使用capistrano从rails 3升级到rails 4,现在图像资产没有显示。(Upgrade from rails 3 to rails 4 with capistrano, now image assets are not showing. Why?)
rails资产管道产生了javascript(rails assets pipeline with yielded javascript)
Rails 3.1,资产管道:没有路由匹配(Rails 3.1, asset pipeline: no route matches)
Rails 3.1资产管道:更改默认URL(/ assets)(Rails 3.1 asset pipeline: change default URL (/assets))
Rails 3.1资产管道没有缩小(Rails 3.1 asset pipeline is not minifying)
如何让Rails 3.1使用新的Assets Pipeline?(How do I get Rails 3.1 to use the new Assets Pipeline?)
逐步升级到Rails资产管道(Incrementally upgrading to Rails assets pipeline)
Rails升级到bootstrap 4(Rails upgrading to bootstrap 4)
Rails 3.1资产管道无法正常工作(Rails 3.1 asset pipeline not working)
相关文章
更多JDBC系列教程之四:SQL注入PreparedStatement和Statement
sql问题
问一条sql语句
sql 语句
如何优化这个sql语句
《JAVA代码规范》(六)通用代码格式 - 语句、SQL(2.9-2.10)
不会sql语句....谁帮我优化下
sql语句-关于行列互换等问题的查询语句
SQL Server 压力测试
最新问答
更多获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
如何通过引用返回对象?(How is returning an object by reference possible?)
矩阵如何存储在内存中?(How are matrices stored in memory?)
每个请求的Java新会话?(Java New Session For Each Request?)
css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
xcode语法颜色编码解释?(xcode syntax color coding explained?)
在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!