推送到生产后模板错误

时间:2013-12-06 21:45:32

标签: ruby-on-rails

Ruby:2 * Rails:4 *

我最近在orders模型上设置了belongs_to。我将以前称为location的字段更改为location_id,并将其类型从string更改为integer。在我的本地环境中,一切都很棒,但在推送到heroku后 - 我在尝试访问orders/new时收到此错误:

2013-12-06T21:26:51.415564+00:00 app[web.1]: ActionView::Template::Error (undefined method `location_id' for #<Order:0x007f034232d858>):
2013-12-06T21:26:51.415564+00:00 app[web.1]: 
2013-12-06T21:26:51.415564+00:00 app[web.1]:   app/views/orders/new.html.erb:4:in `_app_views_orders_new_html_erb___1199879637359872052_69825989547780'
2013-12-06T21:26:51.415564+00:00 app[web.1]:     23:     <%= f.label :location_id %><br>
2013-12-06T21:26:51.415564+00:00 app[web.1]:     22:   <div class="field">
2013-12-06T21:26:51.415722+00:00 app[web.1]:   app/views/orders/_form.html.erb:24:in `block in _app_views_orders__form_html_erb___1716646795441888489_69825989572420'
2013-12-06T21:26:51.415722+00:00 app[web.1]:     26:   <div class="field">
2013-12-06T21:26:51.415564+00:00 app[web.1]:     24:     <%= f.select :location_id, @locations, prompt: "Select One" %>
2013-12-06T21:26:51.415564+00:00 app[web.1]:     21:   </div>
2013-12-06T21:26:51.415722+00:00 app[web.1]:     25:   </div>

一切都在本地运作,但为了完整起见,这里有一点额外的内容:

来自orders_controller的2段摘录

def new
    @locations = Location.all.collect { |l| [l.name, l.id]}
    if @cart.line_items.empty?
      redirect_to store_url, notice: "Your cart is empty"
      return
    end

    @order = Order.new
end

def order_params
  params.require(:order).permit(:name, :notes, :email, :location_id)
end

来自有问题的表单:

<div class="field">
    <%= f.label :location_id %><br>
    <%= f.select :location_id, @locations, prompt: "Select One" %>
</div>

我缺少什么?

1 个答案:

答案 0 :(得分:0)

你是否进行了迁移?

heroku run rake db:migrate