我想实现一个订单页面,但这太难了.
这个系统是葡萄牙语,出于其他原因,对此表示遗憾。
我的看法是:
conta/pedidos/index.html.erb
<h3>Meus pedidos</h3>
<table>
<thead>
<th>#</th>
<th>Data do pedido</th>
</thead>
<tbody>
<% @pedidos.each do |pedido| %>
<tr>
<td><%= link_to pedido.id, pedido_path(pedido.token) %></td>
<td><%= pedido.create_at.to_s(:long) %></td>
</tr>
<% end %>
</tbody>
</table>我的控制器:
conta/pedidos_controller.rb
class Conta::PedidosController < ApplicationController
before_action :authenticate_usuario!
def index
@pedidos = current_usuario.pedidos.order("id DESC")
end
end我的模特:
pedido.rb
class Pedido < ActiveRecord::Base
belongs_to :pessoa
has_many :itens, class_name: "ItemPedido" , dependent: :destroy
accepts_nested_attributes_for :enderecos
before_create :gerar_token
def gerar_token
self.token = SecureRandom.uuid
end
end而错误是:
ArgumentError in Conta::PedidosController#index
No association found for name `enderecos'. Has it been defined yet?拜托,我做了什么?
发布于 2016-02-15 22:02:53
我不知道你为什么在accepts_nested_attributes_for :enderecos in pedido.rb。在提供的代码中没有提到它。你能简单地评论/删除它吗?
如果需要,则需要为其设置关联:可能是has_many :enderecos
https://stackoverflow.com/questions/35419527
复制相似问题