0

我的应用程序在 localhost 中运行良好,但是当我部署到 heroku 并尝试创建新订单时,我收到此错误:

2013-03-20T21:26:02+00:00 app[web.1]: Started GET "/orders/new" for 189.44.29.3 at 2013-03-20 21:26:02 +0000
2013-03-20T21:26:02+00:00 app[web.1]: Processing by OrdersController#new as HTML
2013-03-20T21:26:02+00:00 app[web.1]:   Rendered orders/new.html.erb within layouts/application (49.4ms)
2013-03-20T21:26:02+00:00 app[web.1]: Completed 500 Internal Server Error in 62ms
2013-03-20T21:26:02+00:00 app[web.1]: 
2013-03-20T21:26:02+00:00 app[web.1]: ActionView::Template::Error (/app/app/views/orders/new.html.erb:31: unknown regexp options - tabl
2013-03-20T21:26:02+00:00 app[web.1]: /app/app/views/orders/new.html.erb:33: unterminated string meets end of file
2013-03-20T21:26:02+00:00 app[web.1]: /app/app/views/orders/new.html.erb:33: syntax error, unexpected $end, expecting keyword_end):
2013-03-20T21:26:02+00:00 app[web.1]:     28:       <td><%= order.select :drop,options_for_select({"Nao",false,"Sim",true}) %></td>
2013-03-20T21:26:02+00:00 app[web.1]:     29:   </tr>
2013-03-20T21:26:02+00:00 app[web.1]:     30:   </tbody>
2013-03-20T21:26:02+00:00 app[web.1]:     31: </table>
2013-03-20T21:26:02+00:00 app[web.1]:     32:   <%= order.submit "Criar nova Compra !"%>
2013-03-20T21:26:02+00:00 app[web.1]:     33: <% end %>
2013-03-20T21:26:02+00:00 app[web.1]:   app/controllers/orders_controller.rb:16:in `new'

在我看来有这个代码:

<%= form_for @order do |order| %>
<table>
    <tbody>
    <tr>
        <td>Fornecedor</td>
        <td>Produto</td>
        <td>Quantidade</td>
        <td>Nr Compra</td>
        <td>Pagamento</td>
        <td>Valor</td>
        <td>Endereço</td>
        <td>Dropship</td>
    </tr>
    <tr>
        <td><%= order.select :seller,Place.all.map { |a| [a.place,a.place] }%></td>
        <td><%= order.select :product_id,Product.all.map { |a| [a.name,a.id] } %></td>
        <td><%= order.text_field :quantity,:size => 4 %></td>
        <td><%= order.text_field :order_number,:size => 2%></td>
        <td><%= order.select :payment,Place.all.map { |a| [a.place,a.place] }%></td>
        <td><%= order.text_field :value,:size => 5 %></td>
        <td><%= order.select :adress_id,Adress.all.map { |a| [a.name,a.id] }%></td>
        <td><%= order.select :drop,options_for_select({"Nao",false,"Sim",true}) %></td>
    </tr>
    </tbody>
</table>
    <%= order.submit "Criar nova Compra !"%>
<% end %>

如果有人可以帮助我,谢谢,当我尝试创建新订单时会发生此错误,谢谢

我尝试使用options_for_select和whitout,所有情况下我都会在heroku中遇到这个错误!

4

1 回答 1

1

您的视图中有语法错误。我最好的猜测是,对于您的情况,是以下行

<td><%= order.select :drop,options_for_select({"Nao",false,"Sim",true}) %></td>
</tr>

可以改写为:

<td><%= order.select :drop,options_for_select({"Nao" => false, "Sim" => true}) %></td>
</tr>

该表达式{"Nao",false,"Sim",true}在默认的 Ruby 语法中没有任何意义。

更改为此{"Nao" => false,"Sim" => true}将产生一个哈希。

更改为此["Nao",false,"Sim",true]将生成一个数组。

根据文档,rails 方法options_for_select将接受散列或数组(或任何可枚举类型)。

于 2013-03-21T04:08:46.610 回答