Ruby on rails ActionView::Template::Error(订单:0x007f4641e56198>;的未定义方法“交货日期和交货日期”):
当我部署到heroku并尝试创建一个嵌套在merchants中的新订单时,我会看到“我们很抱歉!出现了问题!”页面。它在localhost上运行得很好,但在heroku中却不行。我已经完成了“Heroku run rake db:migrate”和“Heroku restart”,但这并没有解决问题。我是rails/heroku的新手,不知道如何验证heroku DB中是否存在该列。我非常感谢你的帮助 这就是我得到的错误:Ruby on rails ActionView::Template::Error(订单:0x007f4641e56198>;的未定义方法“交货日期和交货日期”):,ruby-on-rails,heroku,undefined,actionview,Ruby On Rails,Heroku,Undefined,Actionview,当我部署到heroku并尝试创建一个嵌套在merchants中的新订单时,我会看到“我们很抱歉!出现了问题!”页面。它在localhost上运行得很好,但在heroku中却不行。我已经完成了“Heroku run rake db:migrate”和“Heroku restart”,但这并没有解决问题。我是rails/heroku的新手,不知道如何验证heroku DB中是否存在该列。我非常感谢你的帮助 这就是我得到的错误: ←[36m2014-07-23T05:52:48.756234+
←[36m2014-07-23T05:52:48.756234+00:00 app[web.1]:←[0m Processing by OrdersController#new as HTML
←[36m2014-07-23T05:52:48.756243+00:00 app[web.1]:←[0m Parameters: {"merchant_id"=>"3"}
←[36m2014-07-23T05:52:48.794320+00:00 app[web.1]:←[0m Rendered orders/_form.html.erb (15.1ms)
←[36m2014-07-23T05:52:48.794384+00:00 app[web.1]:←[0m Rendered orders/new.html.erb within layouts/application (17.1ms)
←[36m2014-07-23T05:52:48.794541+00:00 app[web.1]:←[0m Completed 500 Internal Server Error in 38ms
←[33m2014-07-23T05:52:49.199614+00:00 heroku[router]:←[0m at=info method=GET path="/merchants/3/orders/new" host=doordemo-2014.herokuapp.com request_id=ac94d5ce-f387-4cdd-9816-49b3
83d0c0b3 fwd="115.132.128.218" dyno=web.1 connect=4ms service=43ms status=500 bytes=1754
←[36m2014-07-23T05:52:49.156723+00:00 app[web.1]:←[0m Started GET "/merchants/3/orders/new" for 115.132.128.218 at 2014-07-23 05:52:49 +0000
←[36m2014-07-23T05:52:49.192498+00:00 app[web.1]:←[0m
←[36m2014-07-23T05:52:49.192506+00:00 app[web.1]:←[0m 16: <%= f.label :delivery_date %>
←[36m2014-07-23T05:52:49.159989+00:00 app[web.1]:←[0m Parameters: {"merchant_id"=>"3"}
←[36m2014-07-23T05:52:49.192544+00:00 app[web.1]:←[0m app/views/orders/_form.html.erb:17:in `block in _app_views_orders__form_html_erb___3947962364785509298_69969865024340'
←[36m2014-07-23T05:52:49.192545+00:00 app[web.1]:←[0m app/views/orders/_form.html.erb:1:in `_app_views_orders__form_html_erb___3947962364785509298_69969865024340'
←[36m2014-07-23T05:52:49.159930+00:00 app[web.1]:←[0m Processing by OrdersController#new as HTML
←[36m2014-07-23T05:52:49.190336+00:00 app[web.1]:←[0m Completed 500 Internal Server Error in 30ms
←[36m2014-07-23T05:52:49.189961+00:00 app[web.1]:←[0m Rendered orders/_form.html.erb (3.6ms)
←[36m2014-07-23T05:52:49.190131+00:00 app[web.1]:←[0m Rendered orders/new.html.erb within layouts/application (5.6ms)
←[36m2014-07-23T05:52:49.192502+00:00 app[web.1]:←[0m ActionView::Template::Error (undefined method `delivery_date' for #<Order:0x007f4641e56198>):
←[36m2014-07-23T05:52:49.192546+00:00 app[web.1]:←[0m app/views/orders/new.html.erb:10:in `_app_views_orders_new_html_erb___3734469813804991169_69969865000700'
←[36m2014-07-23T05:52:49.192503+00:00 app[web.1]:←[0m 14:
←[36m2014-07-23T05:52:49.192542+00:00 app[web.1]:←[0m 20: <div class="form-group">
←[36m2014-07-23T05:52:49.192505+00:00 app[web.1]:←[0m 15: <div class="form-group">
←[36m2014-07-23T05:52:49.192549+00:00 app[web.1]:←[0m
←[36m2014-07-23T05:52:49.192508+00:00 app[web.1]:←[0m 17: <%= f.text_field :delivery_date, :placeholder => "DD/MM/YYYY", class: "form-control" %>
←[36m2014-07-23T05:52:49.192510+00:00 app[web.1]:←[0m 18: </div>
←[36m2014-07-23T05:52:49.192548+00:00 app[web.1]:←[0m
←[36m2014-07-23T05:52:49.192511+00:00 app[web.1]:←[0m 19:
←[33m2014-07-23T05:52:49.899149+00:00 heroku[router]:←[0m at=info method=GET path="/favicon.ico" host=doordemo-2014.herokuapp.com request_id=8c56c058-361e-4399-94f8-8ddff39347df fw
d="115.132.128.218" dyno=web.1 connect=1ms service=6ms status=304 bytes=133
←[36m2014-07-23T05:52:48.756234+00:00应用程序[web.1]:←[0m由OrdersController处理#新为HTML
←[36m2014-07-23T05:52:48.756243+00:00应用程序[web.1]:←[0m参数:{“商户id”=>“3”}
←[36m2014-07-23T05:52:48.794320+00:00应用程序[web.1]:←[0m渲染订单/_form.html.erb(15.1ms)
←[36m2014-07-23T05:52:48.794384+00:00应用程序[web.1]:←[0m呈现订单/new.html.erb在布局/应用程序中(17.1ms)
←[36m2014-07-23T05:52:48.794541+00:00应用程序[web.1]:←[0m在38ms内完成500个内部服务器错误
←[33m2014-07-23T05:52:49.199614+00:00 heroku[路由器]:←[0m at=info method=GET path=“/merchants/3/orders/new”host=doordemo-2014.herokuapp.com请求_id=ac94d5ce-f387-4cdd-9816-49b3
83d0c0b3 fwd=“115.132.128.218”dyno=web.1 connect=4ms服务=43ms状态=500字节=1754
←[36m2014-07-23T05:52:49.156723+00:00应用程序[web.1]:←2014-07-23 05:52:49+0000时115.132.128.218的[0m开始获取“/商户/3/订单/新”
←[36m2014-07-23T05:52:49.192498+00:00应用程序[web.1]:←[0m
←[36m2014-07-23T05:52:49.192506+00:00应用程序[web.1]:←[16:
←[36m2014-07-23T05:52:49.159989+00:00应用程序[web.1]:←[0m参数:{“商户id”=>“3”}
←[36m2014-07-23T05:52:49.192544+00:00应用程序[web.1]:←[0m app/views/orders/_form.html.erb:17:in`block in_app_views_orders_form_html_erb_3947962364785509298_69969865024340'
←[36m2014-07-23T05:52:49.192545+00:00应用程序[web.1]:←[0m app/views/orders/_form.html.erb:1:in`` app\u views\u orders\u form\u html\u erb\u 3947962364785509298\u 69969865024340'
←[36m2014-07-23T05:52:49.159930+00:00应用程序[web.1]:←[0m由OrdersController处理#新为HTML
←[36m2014-07-23T05:52:49.190336+00:00应用程序[web.1]:←[0m在30毫秒内完成500个内部服务器错误
←[36m2014-07-23T05:52:49.189961+00:00应用程序[web.1]:←[0m渲染订单/_form.html.erb(3.6ms)
←[36m2014-07-23T05:52:49.190131+00:00应用程序[web.1]:←[0m呈现订单/new.html.erb在布局/应用程序中(5.6ms)
←[36m2014-07-23T05:52:49.192502+00:00应用程序[web.1]:←[0m ActionView::Template::Error(未定义#的“交货日期”方法):
←[36m2014-07-23T05:52:49.192546+00:00应用程序[web.1]:←[0m app/views/orders/new.html.erb:10:在`_app_views_orders_new_html_erb_3734469813804991169_69969865000700'中
←[36m2014-07-23T05:52:49.192503+00:00应用程序[web.1]:←[14:
←[36m2014-07-23T05:52:49.192542+00:00应用程序[web.1]:←[20:
←[36m2014-07-23T05:52:49.192505+00:00应用程序[web.1]:←[15:
←[36m2014-07-23T05:52:49.192549+00:00应用程序[web.1]:←[0m
←[36m2014-07-23T05:52:49.192508+00:00应用程序[web.1]:←[0m 17:“日/月/年”,类别:“表格控制”%>
←[36m2014-07-23T05:52:49.192510+00:00应用程序[web.1]:←[18:
←[36m2014-07-23T05:52:49.192548+00:00应用程序[web.1]:←[0m
←[36m2014-07-23T05:52:49.192511+00:00应用程序[web.1]:←[19:
←[33m2014-07-23T05:52:49.899149+00:00 heroku[路由器]:←[0m at=info method=GET path=“/favicon.ico”host=doordemo-2014.herokuapp.com请求\u id=8c56c058-361e-4399-94f8-8ddff39347df fw
d=“115.132.128.218”dyno=web.1连接=1ms服务=6ms状态=304字节=133
_形成局部
<%= form_for([@merchant, @order]) do |f| %> <!--Trial 1-->
<% if @order.errors.any? %>
<div id="error_explanation" class="alert alert-danger dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<h4><%= pluralize(@order.errors.count, "error") %> prohibited this order from being saved:</h4>
<ul>
<% @order.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="form-group">
<%= f.label :delivery_date %>
<%= f.text_field :delivery_date, :placeholder => "DD/MM/YYYY", class: "form-control" %>
</div>
<div class="form-group">
<%= f.label :delivery_time %>
<%= f.text_field :delivery_time, :placeholder => "HH:MM AM/PM", class: "form-control" %>
</div>
<div class="form-group">
<%= f.label :delivery_address %> <span style="color: #CC3300;">(We only deliver to Lintas, Damai & Kota Kinabalu)<span>
<%= f.text_area :address, rows: 3, class: "form-control" %>
</div>
<div class="form-group">
<%= f.label :payment_type %><br>
<%= f.select :pay_type, Order::PAYMENT_TYPES, prompt: 'Select a payment method' %>
</div>
<div class="form-group">
<%= f.submit 'Place Order', class: "btn btn-success" %>
</div>
<% end %>
&时代;
禁止保存此订单:
“DD/MM/YYYY”,类别:“表单控件”%>
“HH:MM AM/PM”,类别:“表单控制”%>
(我们仅向林塔斯、达迈和科塔基纳巴鲁交货)
DB
您似乎已经知道问题可能(几乎可以肯定)是由您的数据库没有delivery\u date
列/属性引起的
正如错误解释的那样
undefined method `delivery_date'
这本质上意味着您的模型
将不具有交货日期
属性,这意味着当您尝试从视图/控制器调用它时,它会认为您没有方法处理它
修复 底线是您需要能够将
delivery\u date
列添加到相应的表中
简单的修复方法是在数据库上执行迁移,考虑到已经为列设置了迁移):
要测试您是否具有列/属性,最好的方法是在Heroku
rails控制台中使用:
$ heroku run rails c
$ [MODEL].attribute_names
$ #-> attribute names outputted. Check for delviery_date
--
如果没有为表设置迁移,则基本上只需在本地启动新迁移,然后使用以下内容填充它:
#dg/migrate/your_new_migration.rb
add_column :datatable, :delviery_date, :string
delivery_date列是否属于order表?请检查所有迁移是否都在serverHello Ahmad&@gotva上运行。我如何执行此操作?如果需要,我可以发布其他内容,以便您了解更多Hello Rich,我尝试过运行[order].attribute_names。它给我运行时错误:自动加载常量顺序时检测到循环依赖项。我该怎么办?抱歉,Rich,现在我看到了属性名称,是的,我没有看到交付日期。我将尝试启动新迁移。我尝试添加新迁移并使用rake db:migrate Local,但由于dupl,我遇到了一个错误我只是跳过rake db:migrate,然后把它推到github和heroku?然后heroku运行rake db:migrate?解决了!谢谢Rich:)
#dg/migrate/your_new_migration.rb
add_column :datatable, :delviery_date, :string