Skip to content

Instantly share code, notes, and snippets.

@aristotelesbr
Last active August 29, 2015 14:13
Show Gist options
  • Save aristotelesbr/dbcf7d554a7995a7d997 to your computer and use it in GitHub Desktop.
Save aristotelesbr/dbcf7d554a7995a7d997 to your computer and use it in GitHub Desktop.
O que esta faltando?
class Venda < ActiveRecord::Base
has_and_belongs_to_many :users
end
class User < ActiveRecord::Base
has_and_belongs_to_many :vendas
end
class UsersVendas < ActiveRecord::Base
end
Controller Vendas
def index
user = User.find(current_user.id)
@vendas = user.vendas
respond_with(@vendas)
end
E na view de vendas esta assim:
<% @vendas.each do |venda| %>
<tr>
<td><%= link_to venda.id, venda_path(venda) %></td>
<td><%= venda.user.id %></td>
<td><%= venda.produto.nome %></td>
....
<%end%>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment