我是Rails的新手,我正在为我的雇主构建一个简单的项目跟踪应用程序.我一直在我的Mac上开发应用程序并将其推送到github.我只是设法将我的github repo克隆到我公司防火墙后面的一个Windows框中,希望让同事们试用这个应用程序.
但是当我去rake db:migrate来初始化windows框中的数据库时,我收到以下错误消息:
$ rake db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
Could not find table 'projects'
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_reco
rd/connection_adapters/sqlite3_adapter.rb:29:in `table_structure'
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/faker-0.3.1/lib/extensions/object.
rb:3:in `returning'
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_reco
rd/connection_adapters/sqlite3_adapter.rb:28:in `table_structure'
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_reco
rd/connection_adapters/sqlite_adapter.rb:228:in `columns'
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_reco
rd/base.rb:1271:in `columns'
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_reco
rd/base.rb:1279:in `columns_hash'
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_reco
rd/base.rb:1578:in `find_one'
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_reco
rd/base.rb:1569:in `find_from_ids'
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_reco
rd/base.rb:616:in `find'
c:/Rails_Projects/molex_app/config/routes.rb:15
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_contro
ller/routing/route_set.rb:226:in `draw'
c:/Rails_Projects/molex_app/config/routes.rb:1
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_sup
port/dependencies.rb:145:in `load_without_new_constant_marking'
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_sup
port/dependencies.rb:145:in `load'
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_sup
port/dependencies.rb:521:in `new_constants_in'
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_sup
port/dependencies.rb:145:in `load'
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_contro
ller/routing/route_set.rb:286:in `load_routes!'
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_contro
ller/routing/route_set.rb:286:in `each'
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_contro
ller/routing/route_set.rb:286:in `load_routes!'
c:/RubyonRails/Ruby187/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_contro …Run Code Online (Sandbox Code Playgroud) 我希望@messages返回@folder.messages,其中"已删除"列的值不等于true.我不确定为什么这会继续抛出SQLException.我想我没有正确格式化已删除的属性,但我不确定如何解决它.
任何帮助将不胜感激.提前致谢.
错误信息:
ActiveRecord::StatementInvalid in MailboxController#index
SQLite3::SQLException: no such column: true: SELECT "message_copies".* FROM "message_copies" WHERE ("message_copies".folder_id = 1) AND (deleted != true)
Run Code Online (Sandbox Code Playgroud)
应用跟踪:
app/controllers/mailbox_controller.rb:14:in `show'
app/controllers/mailbox_controller.rb:5:in `index'
Run Code Online (Sandbox Code Playgroud)
Mailbox_Controller.rb
1 class MailboxController < ApplicationController
2 def index
3 current_user = User.find(session[:user_id])
4 @folder = Folder.where("user_id = #{current_user.id}").first
5 show
6 render :action => "show"
7 end
8
9 def show
10 current_user = User.find(session[:user_id])
11 @folder = Folder.where("user_id = #{current_user.id}").first
12 @msgs = @folder.messages
13 @ms = @msgs.where("deleted != true") …Run Code Online (Sandbox Code Playgroud) sqlite ruby-on-rails sqlexception sqlite3-ruby ruby-on-rails-3
我在rails 3.0环境中运行rspec.我们刚刚切换到在内存数据库中使用sqlite3进行测试.
要使其工作,您需要在每次运行时加载架构.
这样做的问题在于您从架构加载中获得了大量输出.
根据这一点,似乎Spork以某种方式捕获此输出.所以无论你做什么(silence_stream),架构加载的输出仍将继续通过.
有没有办法在spork中保持沉默?输出会减慢整个测试周期并使其非常烦人.
我正在尝试rvm,并安装了ruby 1.9.2和rails 3.我需要重新安装sqlite3-ruby gem(因为rvm保留所有gem为不同版本的ruby分开).
问题是,当我尝试时,我得到:
gem install sqlite3-ruby
/home/jenny/.rvm/rubies/ruby-1.9.2-p0/bin/gem:4: warning: Insecure world writable dir /home/jenny/.rvm/gems/ruby-1.9.2-p0/bin in PATH, mode 040777
Building native extensions. This could take a while...
ERROR: Error installing sqlite3-ruby:
ERROR: Failed to build gem native extension.
/home/jenny/.rvm/rubies/ruby-1.9.2-p0/bin/ruby extconf.rb
checking for sqlite3.h... yes
checking for sqlite3_libversion_number() in -lsqlite3... yes
checking for rb_proc_arity()... yes
checking for sqlite3_initialize()... yes
checking for sqlite3_next_stmt()... yes
checking for sqlite3_column_database_name()... yes
checking for sqlite3_enable_load_extension()... no
checking for sqlite3_load_extension()... no
creating Makefile
make
gcc -I. -I/home/jenny/.rvm/rubies/ruby-1.9.2-p0/include/ruby-1.9.1/i686-linux …Run Code Online (Sandbox Code Playgroud) 我正在尝试构建一个seeds.rb文件,以便将初始管理员用户添加到数据库中.我有一个Users表和模型,以及一个Roles表和模型.我有一个连接表,roles_users加入用户角色和权限.这是架构:
create_table "roles", :force => true do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "roles_users", :id => false, :force => true do |t|
t.integer "role_id"
t.integer "user_id"
end
create_table "users", :force => true do |t|
t.string "email", :default => "", :null => false
t.string "encrypted_password", :limit => 128, :default => "", :null => false
t.string "reset_password_token"
t.datetime "remember_created_at"
t.integer "sign_in_count", :default => 0
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at"
t.datetime "updated_at"
t.string "first_name"
t.string …Run Code Online (Sandbox Code Playgroud) 我正在创建一个Ruby脚本,将大约150k行的制表符分隔文本文件导入SQLite.到目前为止:
require 'sqlite3'
file = File.new("/Users/michael/catalog.txt")
string = []
# Escape single quotes, remove newline, split on tabs,
# wrap each item in quotes, and join with commas
def prepare_for_insert(s)
s.gsub(/'/,"\\\\'").chomp.split(/\t/).map {|str| "'#{str}'"}.join(", ")
end
file.each_line do |line|
string << prepare_for_insert(line)
end
database = SQLite3::Database.new("/Users/michael/catalog.db")
# Insert each string into the database
string.each do |str|
database.execute( "INSERT INTO CATALOG VALUES (#{str})")
end
Run Code Online (Sandbox Code Playgroud)
尽管gsub在我的prepare_for_insert方法中要转义单引号,但脚本在包含单引号的第一行出错:
/Users/michael/.rvm/gems/ruby-1.9.3-p0/gems/sqlite3-1.3.5/lib/sqlite3/database.rb:91:
in `initialize': near "s": syntax error (SQLite3::SQLException)
Run Code Online (Sandbox Code Playgroud)
这是第15行的错误.如果我检查该行puts string[14],我可以看到它在"s"附近显示错误的位置.它看起来像这样:'Touch …
所以bundle install当我收到此错误时,我试图在我新创建的Rails应用程序中运行:
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby -r ./siteconf20150114-6877-1x6zk4k.rb extconf.rb
checking for sqlite3.h... yes
checking for sqlite3_libversion_number() in -lsqlite3... no
sqlite3 is missing. Try 'port install sqlite3 +universal',
'yum install sqlite-devel' or 'apt-get install libsqlite3-dev'
and check your shared library search path (the
location where your sqlite3 shared library is located).
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file …Run Code Online (Sandbox Code Playgroud) 我是Ruby on Rails的新手,我使用SQLite3作为我的示例项目的数据库.我试图在两个模型之间创建普通的一对多关系(例如,每个产品有一个所有者,每个所有者可以有许多产品).这很好,并且正确创建了数据库模式.但是,当我在数据库管理工具中打开development.sqlite3时(我使用免费的SQLite Express Personal http://www.sqliteexpert.com/download.html)我没有看到该数据库具有参照完整性.即使包含owner_id列,也没有为Product表列出外键.
我尝试通过添加选项键来更改database.yml:
default: &default
adapter: sqlite3
pool: 5
timeout: 5000
options: "PRAGMA foreign_keys=ON"
Run Code Online (Sandbox Code Playgroud)
然后重新创建数据库:
rake db:drop db:create db:migrate
Run Code Online (Sandbox Code Playgroud)
这会重新创建数据库,但同样没有列出外键.
难道我做错了什么?是否有解决方案.(PS.如果这很重要,我在Windows 8.1上运行所有这些)
当我尝试运行Ruby on Rails应用程序时......我面临以下错误
符号查找错误:/home/user/.rvm/gems/ruby-1.9.2-preview3/gems/sqlite3-ruby-1.3.0/lib/sqlite3/sqlite3_native.so:undefined symbol:sqlite3_initialize
我不知道这个错误究竟是什么.任何人都可以帮帮我......
我在Ubuntu系统上工作(16.04).
我的问题是每当我设置任何rails项目并尝试运行rails s然后我得到'不兼容的库版本'错误sqlite3如下所示.
/home/jiggs/.rvm/gems/ruby-2.3.1@albumriver/gems/activesupport-4.0.0/lib/active_support/values/time_zone.rb:282: warning: circular argument reference - now
/home/jiggs/.rvm/gems/ruby-2.3.1@albumriver/gems/sqlite3-1.3.11/lib/sqlite3.rb:6:in `require': incompatible library version - /home/jiggs/.rvm/gems/ruby-2.3.1@albumriver/gems/sqlite3-1.3.11/lib/sqlite3/sqlite3_native.so (LoadError)
from /home/jiggs/.rvm/gems/ruby-2.3.1@albumriver/gems/sqlite3-1.3.11/lib/sqlite3.rb:6:in `rescue in <top (required)>'
from /home/jiggs/.rvm/gems/ruby-2.3.1@albumriver/gems/sqlite3-1.3.11/lib/sqlite3.rb:2:in `<top (required)>'
from /usr/lib/ruby/vendor_ruby/bundler/runtime.rb:77:in `require'
from /usr/lib/ruby/vendor_ruby/bundler/runtime.rb:77:in `block (2 levels) in require'
from /usr/lib/ruby/vendor_ruby/bundler/runtime.rb:72:in `each'
from /usr/lib/ruby/vendor_ruby/bundler/runtime.rb:72:in `block in require'
from /usr/lib/ruby/vendor_ruby/bundler/runtime.rb:61:in `each'
from /usr/lib/ruby/vendor_ruby/bundler/runtime.rb:61:in `require'
from /usr/lib/ruby/vendor_ruby/bundler.rb:99:in `require'
from /home/jiggs/sites/albumriverfinal/config/application.rb:7:in `<top (required)>'
from /home/jiggs/.rvm/gems/ruby-2.3.1@albumriver/gems/railties-4.0.0/lib/rails/commands.rb:76:in `require'
from /home/jiggs/.rvm/gems/ruby-2.3.1@albumriver/gems/railties-4.0.0/lib/rails/commands.rb:76:in `block in <top (required)>'
from /home/jiggs/.rvm/gems/ruby-2.3.1@albumriver/gems/railties-4.0.0/lib/rails/commands.rb:73:in `tap'
from /home/jiggs/.rvm/gems/ruby-2.3.1@albumriver/gems/railties-4.0.0/lib/rails/commands.rb:73:in `<top (required)>'
from bin/rails:4:in `require' …Run Code Online (Sandbox Code Playgroud) sqlite3-ruby ×10
sqlite ×7
ruby ×6
homebrew ×1
join ×1
migrate ×1
rake ×1
rvm ×1
spork ×1
sqlexception ×1