Rails 迁移 - 未定义的方法`'
Rails migration - undefined method ` '
我们正在尝试将 DB 的列重命名为 rails 约定:
class MakeRailsy < ActiveRecord::Migration
def change
# Classes
rename_table :Classes, :classes_
rename_table :classes_, :classes
rename_column :classes, :ClassID, :id
rename_column :classes, :ClassNO, :class_no
rename_column :classes, :SE, :se
rename_column :classes, :EE, :ee
rename_column :classes, :CE, :ce
rename_column :classes, :MBA, :mba
rename_column :classes, :CS, :cs
rename_column :classes, :AM, :am
rename_column :classes, :ESL, :esl
rename_column :classes, :U_G, :u_g
%w(ClassName DepartmentID SectionNumber InstructorID Units Location
DaysAndTimes Notes Description).each do |column|
rename_column :classes, column, column.underscore
end
但这会引发错误:
-- rename_column(:classes, "ClassName", "class_name")
-> 0.0089s
-- ([])
rake aborted!
StandardError: An error has occurred, all later migrations canceled:
undefined method ` ' for #<MakeRailsy:0x007ffa718e1160>/Users/kellyprice/git/transcript_archives/db/migrate/20150401225004_make_railsy.rb:19:in `block in change'
/Users/kellyprice/git/transcript_archives/db/migrate/20150401225004_make_railsy.rb:18:in `each'
/Users/kellyprice/git/transcript_archives/db/migrate/20150401225004_make_railsy.rb:18:in `change'
NoMethodError: undefined method ` ' for #<MakeRailsy:0x007ffa718e1160>
/Users/kellyprice/git/transcript_archives/db/migrate/20150401225004_make_railsy.rb:19:in `block in change'
/Users/kellyprice/git/transcript_archives/db/migrate/2015040122500
尝试排除 scope/syntax 个错误我试过了,但无济于事:
self.rename_column(:classes, column, column.underscore)
而且,如果您拉平循环并手动调用 rename_column,它似乎可以工作。
您的文件中有一个 unicode space,Ruby 已将其确定为方法调用。这是其中之一:http://www.fileformat.info/info/unicode/char/2002/index.htm
如果您从错误消息中复制 space 并搜索替换为常规 space,我认为应该可以修复它。
在那个循环中似乎有复制和粘贴 en space。
快速搜索和替换:
:%s/ / /g
我们正在尝试将 DB 的列重命名为 rails 约定:
class MakeRailsy < ActiveRecord::Migration
def change
# Classes
rename_table :Classes, :classes_
rename_table :classes_, :classes
rename_column :classes, :ClassID, :id
rename_column :classes, :ClassNO, :class_no
rename_column :classes, :SE, :se
rename_column :classes, :EE, :ee
rename_column :classes, :CE, :ce
rename_column :classes, :MBA, :mba
rename_column :classes, :CS, :cs
rename_column :classes, :AM, :am
rename_column :classes, :ESL, :esl
rename_column :classes, :U_G, :u_g
%w(ClassName DepartmentID SectionNumber InstructorID Units Location
DaysAndTimes Notes Description).each do |column|
rename_column :classes, column, column.underscore
end
但这会引发错误:
-- rename_column(:classes, "ClassName", "class_name")
-> 0.0089s
-- ([])
rake aborted!
StandardError: An error has occurred, all later migrations canceled:
undefined method ` ' for #<MakeRailsy:0x007ffa718e1160>/Users/kellyprice/git/transcript_archives/db/migrate/20150401225004_make_railsy.rb:19:in `block in change'
/Users/kellyprice/git/transcript_archives/db/migrate/20150401225004_make_railsy.rb:18:in `each'
/Users/kellyprice/git/transcript_archives/db/migrate/20150401225004_make_railsy.rb:18:in `change'
NoMethodError: undefined method ` ' for #<MakeRailsy:0x007ffa718e1160>
/Users/kellyprice/git/transcript_archives/db/migrate/20150401225004_make_railsy.rb:19:in `block in change'
/Users/kellyprice/git/transcript_archives/db/migrate/2015040122500
尝试排除 scope/syntax 个错误我试过了,但无济于事:
self.rename_column(:classes, column, column.underscore)
而且,如果您拉平循环并手动调用 rename_column,它似乎可以工作。
您的文件中有一个 unicode space,Ruby 已将其确定为方法调用。这是其中之一:http://www.fileformat.info/info/unicode/char/2002/index.htm
如果您从错误消息中复制 space 并搜索替换为常规 space,我认为应该可以修复它。
在那个循环中似乎有复制和粘贴 en space。
快速搜索和替换:
:%s/ / /g