我正在使用带有mysql的RoR制作一个应用程序.我按照以下步骤使用mysql制作应用程序.
1-rails new projectname -d mysql
2-rails生成脚手架帖子标题:弦体:文字
运行第二步后,我收到以下错误.
错误:
Failed to load libmysql.dll from C:\Ruby193\lib\ruby\gems\1.9.1\gems\mysql2-0.3.
18-x86-mingw32\vendor\libmysql.dll
Run Code Online (Sandbox Code Playgroud)
我已经在我的系统中安装了mysql并将libmysql.dll文件从mysql-connector-c-noinstall-6.0.2-win32\lib\libmysql.dll复制到C:\ Ruby193\bin仍然我收到了上述错误.请将尝试帮助我解决这个错误,我也有兴趣知道我的mysql数据库是否存在于其他实例而不是我的本地系统如何使用Rails连接它.
我在我的系统中使用Rails版本-3.2.19和win-xp.
我有一个疑问。假设我已经在 Rails 3 应用程序中创建了模型(即用户)。现在我将我的应用程序连接到其他数据库(比如 SQL Server)而不是我的数据库(我之前在那里创建了这个模型)。我要连接的那个数据库没有“用户”表,我的应用程序已经有 User.rb 文件。在这里我需要什么时候我将我的应用程序连接到那个数据库,它会自动执行查询并在那个数据库中创建表.请检查下面给出的我的用户迁移文件。
20150419131135_create_users.rb:
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :contact_name
t.string :login_id
t.string :password_hash
t.string :password_salt
t.string :phone
t.string :address
t.timestamps
end
end
end
Run Code Online (Sandbox Code Playgroud)
用户.rb:
class User < ActiveRecord::Base
attr_accessible :address, :contact_name, :login_id, :password_hash, :password_salt, :phone,:password, :password_confirmation
attr_accessor :password
before_save :encrypt_password
validates_confirmation_of :password
validates_presence_of :password, :on => :create
validates :contact_name, :presence => true, :length => { :minimum => 5 }
validates :login_id, :presence => true
validates_uniqueness_of :login_id
def encrypt_password …
Run Code Online (Sandbox Code Playgroud)