Tag: mysql

对于#<ActiveRecord :: ConnectionAdapters :: MysqlAdapter,未定义的方法`explain'

我是Ruby on Rails的新手,但我已经学过一些教程,并且知道我的方法。 我已经生成了一些脚手架并将数据插入到MySql数据库中。 导航到index.html.erb时,我收到标题中的错误 控制器正在执行索引 def index @beers = Beer.all respond_to do |format| format.html # index.html.erb format.json { render :json => @beers } end end 并将此作为一种结构 Beer: id, brewer_id, name, price, score, color, brew_type, create_at, updated_at RoR正在为我创建的其他脚手架工作,并列出数据。 我更新了实体Beer的mysql结构,它可能没有反映rails的变化(dunno)。 我是否需要一个不同的gem来将rails连接到mysql db? 任何关于检查什么的建议都将受到赞赏(:

在Ubuntu上运行Rails时遇到问题

首先是一些背景。 我正在尝试在全新安装的Ubuntu上运行Community Engine 。 CE是一个在Rails上运行的开放式src社交网络插件。 我能够在没有问题的情况下在我的Windows机器上运行CE并运行。 我现在决定使用Ubuntu 8.10作为我的开发环境,并坚持这个问题。 我在过去的几个晚上研究了这个,但仍然卡住了。 当我到达指令的这一步( 在此处找到 )时会发生什么: Generate the community engine migrations: $ script/generate plugin_migration 我收到以下错误: myuser@compy:~/Projects/MyProject$ script/generate plugin_migration /home/myuser/Projects/MyProject/config/../vendor/plugins/engines/boot.rb:4: This version of the engines plugin requires Rails 2.1.1 or later! (RuntimeError) from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require’ from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require’ from /home/myuser/Projects/MyProject/config/environment.rb:12 from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require’ from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require’ from /home/myuser/Projects/MyProject/vendor/rails/railties/lib/commands/generate.rb:1 from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in […]

在rails中创建新对象时出错

每当我尝试为模型创建对象时,我都会在rails中收到此错误。 我正在使用Windows 7 C:\Ruby\joker\chapter3>ruby script/console Loading development environment (Rails 2.3.8) >> mycb = ComicBook.new SyntaxError: C:/Ruby/joker/chapter3/app/models/comic_book.rb:19: syntax error, u nexpected $end, expecting kEND from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_suppo rt/dependencies.rb:380:in `load_without_new_constant_marking’ from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_suppo rt/dependencies.rb:380:in `load_file’ from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_suppo rt/dependencies.rb:521:in `new_constants_in’ from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_suppo rt/dependencies.rb:379:in `load_file’ from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_suppo rt/dependencies.rb:259:in `require_or_load’ from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_suppo rt/dependencies.rb:425:in `load_missing_constant’ from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_suppo rt/dependencies.rb:80:in `const_missing’ from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_suppo rt/dependencies.rb:92:in `const_missing’ […]

Ruby on Rails Mysql2 ::错误:表’pages’已经存在:CREATE TABLE`page`但无法迁移回来

我试图运行迁移但是在第一次尝试运行它时错过了t.integer“subject_id”中的一行。 迁移看起来像这样: class CreatePages false t.timestamps end add_index(“pages”, “subject_id”) add_index(“pages”, “permalink”) end def down drop_table :pages end end 以上现在似乎是正确的,但当我尝试再次运行时,我得到了这个: George$ rake db:migrate == 20150110112705 CreatePages: migrating ====================================== — create_table(:pages) rake aborted! StandardError: An error has occurred, all later migrations canceled: Mysql2::Error: Table ‘pages’ already exists: CREATE TABLE `pages` (`id` int(11) auto_increment PRIMARY KEY, `subject_id` int(11), […]

试图在现有的mysql db上构建rails 3.2 app

我试图弄清楚如何在现有的mysql数据库之上构建一个rails应用程序。 我认为最好的方法就是创建一个与现有数据库布局相同的迁移,但我不太清楚如何做到这一点,然后连接它。 我知道这篇文章使用现有的Mysql数据库构建Ruby on Rails应用程序 但我仍然不确定; 我只是这样做,但我需要的列? 此问题的主要答案是说我应该将我的数据库设为csv然后导入它,是否有人有他们推荐的教程或gem?

在ruby中运行rake导入任务时内存不足

我正在运行一项任务来导入大约100万个订单。 我循环遍历数据以将其更新为新数据库上的值,并且它在我的本地计算机上正常工作,具有8 gig的内存。 然而,当我将它上传到我的AWS实例t2.medium它将运行前50万行但是到最后,当它开始实际创建不存在的订单时,我将开始最大化我的记忆。 我正在将一个mysql数据库移植到postgres 我错过了一些明显的东西吗? require ‘mysql2’ # or require ‘pg’ require ‘active_record’ def legacy_database @client ||= Mysql2::Client.new(Rails.configuration.database_configuration[‘legacy_production’]) end desc “import legacy orders” task orders: :environment do orders = legacy_database.query(“SELECT * FROM oc_order”) # init progressbar progressbar = ProgressBar.create(:total => orders.count, :format => “%E, \e[0;34m%t: |%B|\e[0m”) orders.each do |order| if [1, 2, 13, 14].include? […]

Mac OS X Lion – mysql:找不到命令

我从这个源安装了MySQL,安装成功完成。 但是当我在终端中运行哪个mysql时 ,输出为空。 当mysql时 ,输出是 -bash:mysql:找不到命令 另外,我更新了bundle并运行了应用程序 – 结果: /Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/mysql2-0.3.11/lib/mysql2.rb:9:in `require’: Incorrect MySQL client library version! This gem was compiled for 5.5.28 but the client library is 5.6.12. (RuntimeError) 我可以请你帮忙解决这个问题吗? 先感谢您 编辑:我也尝试将gem安装到mysql目录,如 gem install mysql2 — –with-mysql-config=/usr/local/Cellar/mysql/5.5.28/bin/mysql_config 但不幸的是同样 – 成功安装,但当我运行应用程序时,仍然是同样的错误

如何用5个不同的表mysql创建内部查询

Having 5 tables Table a_dates = id, Table b_types = id, a_date_id, c_type_id, Table c_types = id, name, Table d_profiles = id, name, profile_type Table e_ps = id, a_date_id, d_profile_id 从a_dates需要获取b_types,…然后从b_types需要c_types名称,…然后将c_types名称与d_profiles名称进行比较并获取d_profiles id ….如果等于则使用a_date_id,d_profile_id在e_ps中创建记录。 任何人都可以帮助我从内部联接获取查询。 我试过,这是不完整的查询 INSERT INTO e_ps(id,a_date_id,a_date_type,d_profile_id,c_id) SELECT ”,a.id,’A’,dp.id,’67’ FROM d_profiles dp INNER JOIN a_dates a ON {HERE I NEED NAME MATCHING WITH c_types […]

通过共同的关联数排序,即使没有(轨道)

我正在研究一个与此问题有着非常相似的窘境的项目: 按共同关联数量排序(Rails) 问的提问者(霓虹灯)写道, 背景:我有post和用户,都有很多社区。 目标:对于任何给定的用户,我想返回一组post,按照post与用户共有的社区数量排序(更多社区的post更高) 不幸的是,该解决方案仅包括至少有一个共同社区的post。 我的quandry需要包括按共同社区数量排序的所有post。 扩展目标:结果必须是AREL对象, 所有post按公共社区的数量排序,包括与用户共同拥有零社区的post(共同拥有更多社区的post更高)。

在Ruby on Rails应用程序中安装“nokogiri”时出错?

我一直在关注Lynda.com的Ruby on Rails课程。 我完成了video中提到的一切。 我正在尝试运行rails server命令,它应该默认为WEBrick,对吗? 我运行命令,它在nokogiri.rb文件和第29行有一个问题,其中发生错误这是读取的内容: require ‘nokogiri/nokogiri’ 这是我的命令提示符在运行rails server命令时呕吐的原因。 什么可能导致这个? 如果是这样,我需要运行什么命令来解决这个问题? 对我来说,这听起来像安装MySQL时错过了一些东西。 我不确定nokogiri是什么以及为什么rails server不会运行并指向该行代码。 此文件的路径是(Wherever you installed the folder to)\lib\ruby\gems\2.2.0\gems\nokogiri-1.6.6.2-x64-mingw32\lib 编辑**:我有一系列错误,比如它来自-long path-,from-longpath-等。 我尝试安装最新的gem,但没有成功。 是否有一个日志文件,我可以与您分享,以帮助找出问题。