Entry view form

46 views
Skip to first unread message

Chris Ashfield

unread,
Aug 7, 2018, 1:19:23 PM8/7/18
to plutus-gem
If anyone has a custom view entry form that works, I'd love to see it. I got a new account view to work and moved on to entries. However, the closest I came was:

Controller:

def create
  @entry = Plutus::Entry.new(entry_params)
end

private

  def entry_params
  params.require(:entry).permit(:description, :date, :debits => [:account_name, :amount], :credits => [:account_name, :amount] )
  end

View:

<%= form_for(@entry, url:entries_new_path) do |f| %>
<table>
<tr>
<th>Description</th>
<th>Date</th>
<th>Debit Amount</th>
<th>Debit Account</th>
<th>Credit Amount</th>
<th>Credit Account</th>
</tr>
<tr>
<td><%= f.text_field :description %></td>
<td><%= f.date_select :date %></td>
<td><%= text_field Plutus::DebitAmount, :debit_amount %></td>
<td><%= collection_select(Plutus::Account, :id, Plutus::Account.all, :id, :name, :prompt => true) %></td>
<td><%= text_field Plutus::CreditAmount, :credit_amount %></td>
<td><%= collection_select(Plutus::Account, :id, Plutus::Account.all, :id, :name, :prompt => true) %></td>
</tr>
</table>
<br />
<%= f.submit "Create new entry", class: "btn btn-primary" %>
<% end %>


Notice the "f" removed from the collection_selects and text_fields for the inherited parameters (because Rails complained I couldn't act on the @entry if I kept them. This produces an entry assembly that doesn't work: 

Output:

Parameters: {"utf8"=>"✓", "authenticity_token"=>"GNq+RmAQLbczxb0SpYI9m0qF8XvQwdZoOGuQoajfJh3SUqsz76durN/mLR3I/Nw6xFdH8U+Trw2cEOvbZlq+hQ==", 
"entry"=>{"description"=>"Order placed for widgets", "date(1i)"=>"2018", "date(2i)"=>"8", "date(3i)"=>"7"}, 
"Plutus::DebitAmount"=>{"debit_amount"=>"100"}, 
"Plutus::Account"=>{"id"=>"6"}, "Plutus::CreditAmount"=>{"credit_amount"=>"100"}, 
"commit"=>"Create new entry"}

NOte that the second Account (for credits) is missing completely, and the nesting of debits and credits didn't occur (see below):

Versus the output necessary via the readme:

entry = Plutus::Entry.new(
                :description => "Order placed for widgets",
                :date => Date.yesterday,
                :debits => [{:account_name => "Cash", :amount => 100.00}],
                :credits => [{:account_name => "Unearned Revenue", :amount => 100.00}])
entry.save

Von Christian Halip

unread,
Jan 10, 2019, 7:57:34 AM1/10/19
to plutus-gem
It is simpler to have a Form Object that supports your entry creation. 

#/forms/entry_creation.rb
   
  class EntryCreation
    include ActiveModel::Model
    attr_accessor :description, :date, :debit_account, :debit_amount, :credit_account :credit_amount]
  
  def save 
    create_entry 
  end 
  
  private 
  
  def create_entry 
    entry = Plutus::Entry.build(
      description: description,
      date: date
    entry.debit_amounts.build(
      amount: debit_amount,
      account: debit_account)
    entry.credit_amounts.build(
      amount: credit_amount,
      account: credit_account)
    entry.save!
   end 
  end 
end

#controller 
def create
  @entry = EntryCreation.new(entry_params)
end

private

  def entry_params
   params.require(:entry_creation).permit(:description, :date, :debit_account_id, :amount, :credit_account_id, :credit_amount)
  end

Don Wildman

unread,
Jan 10, 2019, 12:17:00 PM1/10/19
to plutu...@googlegroups.com
My entries are created through allocations from bank statements and the capturing of things like assets and expenses, I can't do it that way. Thanks for your input, I'll be happy to share anything I come up with.

--
You received this message because you are subscribed to the Google Groups "plutus-gem" group.
To unsubscribe from this group and stop receiving emails from it, send an email to plutus-gem+...@googlegroups.com.
To post to this group, send email to plutu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/plutus-gem/5f0996ef-11d3-4678-90b4-8c5187f07664%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages