Ruby on rails rails\u sql\u视图错误?
我正在尝试使用迁移来管理我的SQL Server视图。我找到了rails\u sql\u views扩展,它看起来正是我所需要的,但是我在运行迁移时遇到了一个我无法理解的错误。以下是错误:Ruby on rails rails\u sql\u视图错误?,ruby-on-rails,ruby-on-rails-3,Ruby On Rails,Ruby On Rails 3,我正在尝试使用迁移来管理我的SQL Server视图。我找到了rails\u sql\u views扩展,它看起来正是我所需要的,但是我在运行迁移时遇到了一个我无法理解的错误。以下是错误: rake aborted! An error has occurred, this and all later migrations canceled: uninitialized constant CreateFunds 以下是我的迁移: class CreateFundView < Active
rake aborted!
An error has occurred, this and all later migrations canceled:
uninitialized constant CreateFunds
以下是我的迁移:
class CreateFundView < ActiveRecord::Migration
def up
create_view :v_funds, "SELECT * from funds"
end
def down
drop_view :v_funds
end
end
class CreateFundView < ActiveRecord::Migration
def up
create_view :funds,
"SELECT TOP (100) PERCENT
FUND.FUND_ID AS [fund_id],
FUND.DESCRIPTION AS [fund_description],
FUND_FUND_CATEGORY.LONGDESCRIPTION AS [fund_category],
FUND.NOTES AS [fund_notes]
FROM
RE7.dbo.FUND AS FUND LEFT OUTER JOIN
RE7.dbo.TABLEENTRIES AS FUND_FUND_CATEGORY ON FUND.FUND_CATEGORY = FUND_FUND_CATEGORY.TABLEENTRIESID
WHERE (FUND.FUNDTYPE = 23702)
ORDER BY [fund_description]"
end
def down
drop_view :funds
end
end
class CreateFundView
我使用的是Rails 3.1.1。
有人能帮我吗 我让它工作起来,我将rails_sql_views gem升级为与rails 3.1.1兼容的版本。 (至少我认为这是解决问题的办法!)。下面是一个链接,指向正在运行的gem: 以下是一个工作迁移:
class CreateFundView < ActiveRecord::Migration
def up
create_view :v_funds, "SELECT * from funds"
end
def down
drop_view :v_funds
end
end
class CreateFundView < ActiveRecord::Migration
def up
create_view :funds,
"SELECT TOP (100) PERCENT
FUND.FUND_ID AS [fund_id],
FUND.DESCRIPTION AS [fund_description],
FUND_FUND_CATEGORY.LONGDESCRIPTION AS [fund_category],
FUND.NOTES AS [fund_notes]
FROM
RE7.dbo.FUND AS FUND LEFT OUTER JOIN
RE7.dbo.TABLEENTRIES AS FUND_FUND_CATEGORY ON FUND.FUND_CATEGORY = FUND_FUND_CATEGORY.TABLEENTRIESID
WHERE (FUND.FUNDTYPE = 23702)
ORDER BY [fund_description]"
end
def down
drop_view :funds
end
end
class CreateFundView
类名中是否缺少“s”?或类名与迁移文件名不匹配?已选中所有选项。这里有一个stacktrace,如果有帮助的话;你确定吗?我猜您的迁移文件名类似于db/migrate/20111117101626_create_funds.rb
,该文件中的迁移类名为CreateFundView
,但rails希望找到一个类名CreateFunds
。因此,要么重命名迁移文件,要么更改类名,使它们匹配。