Last active
August 29, 2015 14:13
-
-
Save aristotelesbr/dbcf7d554a7995a7d997 to your computer and use it in GitHub Desktop.
O que esta faltando?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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