【问题标题】:scaffold doesn't work well, the NEW method fails脚手架不好用,新方法失败
【发布时间】:2011-10-31 14:17:10
【问题描述】:

我刚刚执行了这个:

rails g scaffold Photos name:string description:string

并向该模型添加回形针:

rails g paperclip Photo image

当我转到photos/new 时,我得到了这个:

undefined method `model_name' for NilClass:Class

这可能是什么问题?控制器中有@photo = Photo.new,new.html.erb中有form_for(@photo)

感谢您的帮助!

【问题讨论】:

  • 包含您的模型的文件的名称是什么?
  • 您是否运行了迁移并重新启动了服务器?
  • 是的,我都做了,实际上我可以看到数据库中有一个表photos。但是在控制器中:@photo = Photo.new,而在视图中@photo 是nil

标签: ruby-on-rails scaffold


【解决方案1】:

我可能错了,但我认为脚手架总是必须在模型名称中使用单数;将其多元化会导致问题。因此它应该是照片,而不是照片:

rails g scaffold Photo name:string description:string

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-02
    • 2022-09-25
    • 1970-01-01
    • 2012-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多