我们正在尝试将DB列重命名为rails convention:
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
尝试排除我尝试的范围/语法错误,但无济于事:
self.rename_column(:classes, column, column.underscore)
而且,如果你压平循环并手动调用rename_column,它似乎可以工作。
答案 0 :(得分:2)
你的文件中有一个unicode空间,Ruby决定是一个方法调用。它是其中之一:http://www.fileformat.info/info/unicode/char/2002/index.htm
如果您从错误消息中复制空间并使用常规空间搜索替换,我认为应该修复它。
答案 1 :(得分:0)