在rails中定义自定义模型名称

时间:2012-03-16 06:35:40

标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.1

任何人都可以建议我如何定义自定义模型名称。当我试图生成名为3AForm的模型时,它会引发错误。

rails g model 3A_Form date_of_investigation:date date_of_transcription:date by:string                    investigator:string type_of_investigative_activity:text results_of_investigation:text

1 个答案:

答案 0 :(得分:4)

这不起作用,3A_Form不是Ruby中的有效类名。也许你应该试试rails g model Form3A ...。如果您需要将模型连接到具有奇怪名称的现有表格,则可以在班级中使用table_name

class Form3A < ActiveRecord::Base
    self.table_name = 'your_weird_table_name'
    #...
end
相关问题