草庐IT

自定义sql

全部标签

ruby - Rails 3 db :migrate 的未定义方法 `visitor'

我在Rails3中进行数据库迁移时遇到异常。undefinedmethod`visitor'for#编辑请查看解决方案here.在我的项目中没有出现字符串visitor所以我很困惑。这是完整的转储:$rakedb:migrate--trace**Invokedb:migrate(first_time)**Invokeenvironment(first_time)**Executeenvironment**Invokedb:load_config(first_time)**Invokerails_env(first_time)**Executerails_env**Executedb:l

ruby-on-rails - 在 Rails 4.2 中有许多 'finder_sql' 替换

我有一个关联需要一些连接/自定义查询。当试图弄清楚如何实现它时,重复的响应是finder_sql。但是在Rails4.2(及更高版本)中:ArgumentError:Unknownkey::finder_sql我执行连接的查询如下所示:'SELECTDISTINCT"tags".*'\'FROM"tags"'\'JOIN"articles_tags"ON"articles_tags"."tag_id"="tags"."id"'\'JOIN"articles"ON"article_tags"."article_id"="articles"."id"'\'WHEREarticles"."u

sql - Arel 导致聚合无限循环

我在使用Arel聚契约(Contract)一查询中的2列时遇到了问题。当我运行它时,在railsdev-server崩溃之前,整个服务器会卡住一分钟。我怀疑是无限循环:)。也许我误解了Arel的整个概念,如果有人能看一下,我将不胜感激。这个查询的预期结果是这样的:[{:user_id=>1,:sum_account_charges=>300,:sum_paid_debts=>1000},...]a_account_charges=Table(:account_charges)a_paid_debts=Table(:paid_debts)a_participants=Table(:exp

sql - 来自 ActiveRecord::Base.connection.execute(sql) - PostgreSQL 的结果

在使用ActiveRecord::BaseConnection类执行SQL语句后,如何找到PostgreSQL处理的记录数?temp_sql="UPDATEtable_aSETcolumn_a='abc'WHEREcolumn_b=1"result=ActiveRecord::Base.establish_connection(@db).connection.execute(temp_sql)或者您可以建议更好的方法来做到这一点。请记住,上面的更新声明是一个简单的更新声明,以保持问题简短。我真正的查询是“基于集合”的,涉及复杂的创建临时表、更新、插入语句。

sql - Ruby ActiveRecord 和 sql 元组支持

假设底层数据库支持,ActiveRecord是否支持where子句中的元组?生成的where子句类似于:where(name,address)in(('John','123MainSt'))我试过:Person.where({[:name,:address]=>['John','123MainSt']})但它没有用。 最佳答案 tupleArray=[['John','123MainSt'],['Jane','124MainSt']]Person.where("(name,address)IN(#{(['(?)']*tupleArr

ruby - Chrome 的自定义配置文件

环境:MacOSX10.8.3、Ruby2.0.0p0、selenium-webdriver2.32.1、ChromeDriver26.0.1383.0。我想更改默认浏览器语言。我正在测试站点是否正确检测浏览器语言并以该语言显示页面。我能够将Firefox语言设置为德语:require"selenium-webdriver"profile=Selenium::WebDriver::Firefox::Profile.newprofile["intl.accept_languages"]="de"caps=Selenium::WebDriver::Remote::Capabilities.

ruby - 基于 Ruby 语法的未定义局部变量

在下面的Ruby代码中,#!/usr/bin/envrubyx=truey=xandz=yputs"z:#{z}"它将按预期输出z:true。但在下一个中,我希望它具有相同的行为:#!/usr/bin/envrubyx=truez=yify=xputs"z:#{z}"结果undefinedlocalvariableormethod'y'formain:Object(NameError)这是为什么呢?我知道我正在做一个赋值,并隐式检查赋值以确定是否运行z=y。我还了解到,如果我在x=5行之后添加y声明y=nil,它将按预期通过并运行。但是,期望语言应该首先评估if部分,然后评估其内容,然

sql - has_many :through 的索引

假设您有两个模型,User和City,由第三个模型CityPermission加入:classCityPermission:city_permissionsendclassUser:city_permissionsend目前,我使用以下迁移代码片段创建连接表和表索引:create_table:city_permissionsdo|t|t.integer:user_id,:city_idt.other_fields...endadd_index(:city_permissions,:user_id)add_index(:city_permissions,:city_id)这些是要创建的最

ruby - NoMethodError(未定义方法 `[]' 为 nil :NilClass)

我有一个非常奇怪的错误实例:NoMethodError(undefinedmethod`[]'fornil:NilClass):app/controllers/main_controller.rb:150:in`blockinfind_data_label'app/controllers/main_controller.rb:149:in`each'app/controllers/main_controller.rb:149:in`find_data_label'app/controllers/main_controller.rb:125:in`data_string'app/cont

ruby-on-rails - rails 3.2.8 中未定义的 read_inheritable_attribute

升级到rails3.2.8后出现以下错误信息NoMethodError(undefinedmethod`read_inheritable_attribute'forAdminController:Class):谁能解释一下如何解决这个错误?整个轨迹NoMethodError(undefinedmethod`read_inheritable_attribute'forAdminController:Class):vendor/plugins/ssl_requirement/lib/ssl_requirement.rb:45:in`ssl_allowed?'vendor/plugins/s