Permalink
Browse files

Corrigindo Devolução

  • Loading branch information...
andrefaria committed Mar 28, 2012
1 parent f637fe3 commit 44f8e31f351e34dc0449cb93abca4996ce20132f
@@ -29,7 +29,7 @@ def return
end
def confirm_return
@loan = Media.find(params[:id]).loans.last
@loan = Media.find(params[:id]).last_loan
@loan.return
redirect_to @loan.media
end
View
@@ -2,7 +2,7 @@ class Loan < ActiveRecord::Base
belongs_to :media
belongs_to :person
validate :media_is_available
default_scope order('lent_at desc')
default_scope order('lent_at desc, id desc')
def set_return_preview
if self.media and self.media.media_type
@@ -35,4 +35,8 @@ def self.search(media_status_id = nil, page = 1)
end
end
def returned?
returned_at != nil
end
end
View
@@ -2,7 +2,7 @@ class Media < ActiveRecord::Base
belongs_to :media_type, :foreign_key => 'media_type_id'
belongs_to :genre
belongs_to :media_status
has_many :loans
has_many :loans, :order => 'id ASC'
default_scope order('title')
scope :list, joins(:genre)
@@ -40,7 +40,7 @@ def self.search(query, page = 1)
end
def last_loan
self.loans.last
self.loans.first
end
def available?
@@ -7,7 +7,7 @@
%>
<%= button_submit_tag "Buscar", :name => nil %>
<br>
<%= @loans.total_entries %> Pessoa(s) Encontrada(s).
<%= @loans.total_entries %> Empréstimo(s) Encontrado(s).
</p>
<% end %>
</div>
@@ -31,8 +31,8 @@
<td><%= loan.lent_at %></td>
<td><%= loan.return_preview_date %></td>
<td>
<%= loan.returned_at if loan.media.available? %>
<%= pill_positive_button_link_to(t(:return), return_media_path(loan.media)) if loan.media.lent?%>
<%= loan.returned_at if loan.returned? %>
<%= pill_positive_button_link_to(t(:return), return_media_path(loan.media)) unless loan.returned?%>
</td>
</tr>
<% end %>
@@ -31,7 +31,8 @@
<td><%= media.media_status.description unless media.media_status.nil? %></td>
<td>
<%= button_group do %>
<%= pill_positive_button_link_to t(:lend), lend_media_path(media) %>
<%= pill_positive_button_link_to t(:lend), lend_media_path(media) if media.available?%>
<%= pill_positive_button_link_to t(:return), return_media_path(media) if media.lent?%>
<%= pill_button_link_to t(:show), media %>
<%= pill_button_link_to t(:edit), edit_media_path(media) %>
<%= pill_negative_button_link_to t(:destroy), media, :confirm => 'Tem certeza?', :method => :delete %>

0 comments on commit 44f8e31

Please sign in to comment.