Ruby on Rails:类的未定义方法'角色'

时间:2016-03-17 09:24:40

标签: ruby-on-rails heroku

我在Ruby on Rails应用程序中遇到了问题。我有一个名为'Hairdresser'的实体,具有以下属性:

irb(main):003:0> Hairdresser
=> Hairdresser(id: integer, name: string, surname: string, email: string, auth_token: string, password_digest: string, created_at: datetime, updated_at: datetime, facebook_id: string, first_login: boolean, role: string)

我还创建了一些脚手架以创建新的美发师实体,但当我点击“新美发师”时,我收到以下错误:

2016-03-17T09:14:43.063793+00:00 app[web.1]: ActionView::Template::Error (undefined method `role' for #<Hairdresser:0x007f9e20f2bc30>):
2016-03-17T09:14:43.063794+00:00 app[web.1]:     25:   </div>
2016-03-17T09:14:43.063794+00:00 app[web.1]:     26:   <div class="field">
2016-03-17T09:14:43.063795+00:00 app[web.1]:     27:     <%= f.label :role %><br>
2016-03-17T09:14:43.063795+00:00 app[web.1]:     28:     <%= f.text_field :role %>
2016-03-17T09:14:43.063795+00:00 app[web.1]:     29:   </div>

角色是我在创建脚手架后添加的属性,但我也将它添加到应该添加的位置(我认为):

查看/美发/ _form.html.erb

  <div class="field">
    <%= f.label :role %><br>
    <%= f.text_field :role %>
  </div>

view / hairdressers / index.html.erb,index.json.jsonbuilder,以及其他/ view / hairdressers文件。

应用程序的本地版本正在运行,它可能与Heroku正在加载生产环境这一事实有关,而在本地主机上我正在运行开发环境吗?

编辑:这是执行heroku run rake --trace db:migrate

** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:migrate
  ActiveRecord::SchemaMigration Load (0.8ms)  SELECT "schema_migrations".* FROM "schema_migrations"
** Invoke db:_dump (first_time)
** Execute db:_dump

1 个答案:

答案 0 :(得分:0)

确保迁移是在heroku上运行的。 https://devcenter.heroku.com/articles/rake

heroku run rake --trace db:migrate