Created
January 23, 2010 15:54
-
-
Save psy-q/284654 to your computer and use it in GitHub Desktop.
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 Invoice < ActiveRecord::Base | |
belongs_to :user | |
has_many :invoice_lines | |
belongs_to :shipping_address, :polymorphic => true | |
belongs_to :billing_address, :polymorphic => true | |
UNPAID = 1 | |
PAID = 2 | |
STATUS_HASH = { UNPAID => 'Unpaid', | |
PAID => 'Paid'} | |
def self.status_to_human(status) | |
return STATUS_HASH[status] | |
end | |
def self.status_hash_for_select | |
hash = [] | |
STATUS_HASH.each do |key,value| | |
hash << [value, key] | |
end | |
return hash | |
end | |
def status_human | |
return Invoice::status_to_human(status_constant) | |
end | |
end | |
# But here the status _shown_ in the pulldown is always 1 | |
# The status _submitted_ via the pulldown is always correct | |
<h2>Edit Invoice</h2> | |
<h4>Shipping address</h4> | |
<%= simple_format @invoice.shipping_address.block_summary %> | |
<h4>Billing address</h4> | |
<%= simple_format @invoice.billing_address.block_summary %> | |
<h4>Items invoiced</h4> | |
<%= render :partial => 'invoice_table', :object => @invoice %> | |
<% debugger %> | |
<% form_for [:admin, @invoice] do |f| %> | |
<table> | |
<tr> | |
<td>Status</td> | |
<td><%= f.select :status_constant, options_for_select(Invoice::status_hash_for_select) %></td> | |
</tr> | |
</table> | |
<%= f.submit "Submit" %> | |
<% end %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment