Pokkai Dokkai wrote:
> Kiki Kiki wrote:
>> hallo, everyone
>> (internal_server_error)
> 
> hai kiki
> could you post that coding part here ?
> it may be helpful

1.in View with name :list_of_balances.html.erb
  <% form_remote_tag(:url => 
filtered_balances_for_a_month_admin_accounts_path(@chart)) do %>
  <p>
    please select a month :
  <%= date_select :filter, :month, :order => [:month,:year], 
:add_month_numbers => true %>
    <%= submit_tag "Filter balances for a month" %>
  </p>
<% end %>

  <div id="balances">
  <%= render :partial => "balances", :locals => {:month => 
Date.today,:begin_date => @begin_date, :end_date => @end_date}%>
</div>

2. in Views with name : _balances.html.erb
  <table class="list">
<tr style="color:red">
  <th><%=h 'account code'%></th>
  <th><%=h 'account name'%> </th>
  <th><%=h 'debit balance'%> </th>
  <th><%=h 'credit balance'%> </th>
</tr>
<% for account in @accounts %>
<tr style="background:<%=cycle("#ccc","")%>;">
   <td><%=h account.code%></td>
   <td><%=h account.name%></td>

   <% if account.debit_sum_between(begin_date,end_date).to_f > 
account.credit_sum_between(begin_date,end_date).to_f%>
     <td><%=h account.debit_sum_between(begin_date, end_date).to_f - 
account.credit_sum_between(begin_date,end_date).to_f %></td>
   <% else %>
     <td><%=h '0.0'%></td>
     <td><%=h account.credit_sum_between(begin_date, end_date).to_f - 
account.debit_sum_between(begin_date,end_date).to_f %></td>
   <% end %>
</tr>
<% end %>
</table>

3. controller File with name accounts_controller.rb
class AccountsController < ApplicationController
  layout "pac"

  before_filter :find_chart

  def find_chart
    @chart = Chartofaccount.find(params[:chartofaccount_id])
  end

  def list_of_balances
    @accounts = Account.find(:all , :order => ['code ASC'],:conditions 
=> ['chartofaccount_id=?',@chart])
    date = Date.today
    @begin_date = date.beginning_of_month
    @end_date = date.end_of_month
  end

   def filtered_balances_for_a_month
    @date = 
Date.new(params[:filter]["month(1i)"].to_i,params[:filter]["month(2i)"].to_i,1)
    @begin_date = @date.beginning_of_month
    @end_date   = @date.end_of_month

    @accounts = Account.find(:all , :order => ['code ASC'],:conditions 
=> ['chartofaccount_id=?',@chart])

    # with p @date , i can know ,here working
    render :update do |page|
      page.replace_html(:balances, :partial => "balances", :locals => 
{:begin_date => @begin_date, :end_date => @end_date})
    end
  end
end

4 routes.rb
  # define of 'admin' is from   colleague

  map.connect 'admin',            :controller   => 'admin/sites',
                                :action       => 'index',
                                :requirements => { :method => :get }
  # this is from my routes
  map.resources :chartofaccounts, :member => { :import_accounts => :get 
},
                                  :controller  => 'chartofaccounts',
                                  :path_prefix => 'admin',
                                  :name_prefix => 'admin_'
  map.resources :accounts, :controller  => 'accounts',
                           :path_prefix => 
'admin/chartofaccounts/:chartofaccount_id',
                           :name_prefix => 'admin_'   ,

                           :collection => {:list_of_balances => :get,
                                           :filtered_balances_for_a_month 
=> :post}

 if other is helpful , tell me please. and thanks .
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to