Forum: Ruby on Rails replace_html not working

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Kiki K. (Guest)
on 2008-10-14 15:39
hallo, everyone

can anybody help me? i did add my code under ENGINES as a module in a
project. before the change , all worked .  and the differenz between
both is only about  application's environment,
before is

Ruby version              1.8.6 (i486-linux)
RubyGems version          1.1.1
Rails version             2.0.2
Active Record version     2.0.2
Action Pack version       2.0.2
Active Resource version   2.0.2
Action Mailer version     2.0.2
Active Support version    2.0.2
Application root          /home/kiki/workspace/xxx
Environment               development
Database adapter          mysql
Database schema version   0

now is

Ruby version              1.8.6 (i486-linux)
RubyGems version          1.1.1
Rails version             2.1.0
Active Record version     2.1.0
Action Pack version       2.1.0
Active Resource version   2.1.0
Action Mailer version     2.1.0
Active Support version    2.1.0
Application root          /home/kiki/workspace/xxxx/
Environment               development
Database adapter          sqlite3
Database schema version   0

and now all function about replace of page not working . maybe the under
informations is helpable.

tail -f log/development.log

    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/../lib/mongrel/configurator.rb:282:in
`run'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/../lib/mongrel/configurator.rb:281:in
`each'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/../lib/mongrel/configurator.rb:281:in
`run'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/mongrel_rails:128:in
`run'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/../lib/mongrel/command.rb:212:in
`run'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/mongrel_rails:281
    /usr/bin/mongrel_rails:19:in `load'
    /usr/bin/mongrel_rails:19

Rendering
/usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/templates/rescues/layout.erb
(internal_server_error)


and the information , when i select a month .

Processing AccountsController#filtered_balances_for_a_month (for
127.0.0.1 at 2008-10-14 13:05:31) [POST]
  Session ID:
BAh7CToUcmV0dXJuX2xvY2F0aW9uQzoeSGFzaFdpdGhJbmRpZmZlcmVudEFj
Y2Vzc3sJIgxzaXRlX2lkIgYyIgthY3Rpb24iCXNob3ciB2lkIgYxIg9jb250
cm9sbGVyIhBhZG1pbi91c2VyczoMY3NyZl9pZCIlOWIyNWYwMzk5ZmFiMjZh
MjhiNmNhMDBhNDkyY2NhNjU6CHVpZGkGIgpmbGFzaElDOidBY3Rpb25Db250
cm9sbGVyOjpGbGFzaDo6Rmxhc2hIYXNoewAGOgpAdXNlZHsA--1a0684d271aa6103b52dbc61c4ad7560443a7f6e
  Parameters: {"commit"=>"Filter balances for a month",
"chartofaccount_id"=>"1",
"authenticity_token"=>"388f45d590a6a0692313241db3f16ee5a5b3b896",
"action"=>"filtered_balances_for_a_month",
"filter"=>{"month(1i)"=>"2008", "month(2i)"=>"9", "month(3i)"=>"1"},
"controller"=>"accounts"}
  Chartofaccount Load (0.000290)   SELECT * FROM "chartofaccounts" WHERE
("chartofaccounts"."id" = 1)
  Account Load (0.001298)   SELECT * FROM "accounts" WHERE
(chartofaccount_id=1) ORDER BY code ASC


ArgumentError (tried to create Proc object without a block):
    /usr/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/core_ext/object/extending.rb:46:in
`define_method'
    /usr/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/core_ext/object/extending.rb:46:in
`instance_exec'
    /usr/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/core_ext/object/extending.rb:46:in
`module_eval'
    /usr/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/core_ext/object/extending.rb:46:in
`instance_exec'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_view/helpers/prototype_helper.rb:581:in
`initialize'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:913:in
`new'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:913:in
`render_with_no_layout'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/layout.rb:259:in
`render_without_benchmark'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/benchmarking.rb:51:in
`render_without_error_proc'
    /usr/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/core_ext/benchmark.rb:8:in
`realtime'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/benchmarking.rb:51:in
`render_without_error_proc'
    /vendor/plugins/render_with_error_proc/lib/action_controller/render_with_error_proc.rb:26:in
`render'
    /vendor/plugins/render_with_error_proc/lib/action_controller/render_with_error_proc.rb:45:in
`with_error_proc'
    /vendor/plugins/render_with_error_proc/lib/action_controller/render_with_error_proc.rb:25:in
`render'
    /vendor/engines/adva_pac/app/controllers/accounts_controller.rb:225:in
`filtered_balances_for_a_month'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:1162:in
`send'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:1162:in
`perform_action_without_filters'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/filters.rb:580:in
`call_filters'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/filters.rb:573:in
`perform_action_without_benchmark'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/benchmarking.rb:68:in
`perform_action_without_rescue'
    /usr/lib/ruby/1.8/benchmark.rb:293:in `measure'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/benchmarking.rb:68:in
`perform_action_without_rescue'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/rescue.rb:201:in
`perform_action_without_caching'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/caching/sql_cache.rb:13:in
`perform_action'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_adapters/abstract/query_cache.rb:33:in
`cache'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/query_cache.rb:8:in
`cache'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/caching/sql_cache.rb:12:in
`perform_action'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:529:in
`send'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:529:in
`process_without_filters'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/filters.rb:569:in
`process_without_session_management_support'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/session_management.rb:130:in
`process'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:389:in
`process'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:149:in
`handle_request'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:107:in
`dispatch'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:104:in
`synchronize'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:104:in
`dispatch'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:120:in
`dispatch_cgi'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:35:in
`dispatch'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/../lib/mongrel/rails.rb:76:in
`process'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/../lib/mongrel/rails.rb:74:in
`synchronize'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/../lib/mongrel/rails.rb:74:in
`process'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/../lib/mongrel.rb:159:in
`process_client'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/../lib/mongrel.rb:158:in
`each'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/../lib/mongrel.rb:158:in
`process_client'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/../lib/mongrel.rb:285:in
`run'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/../lib/mongrel.rb:285:in
`initialize'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/../lib/mongrel.rb:285:in
`new'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/../lib/mongrel.rb:285:in
`run'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/../lib/mongrel.rb:268:in
`initialize'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/../lib/mongrel.rb:268:in
`new'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/../lib/mongrel.rb:268:in
`run'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/../lib/mongrel/configurator.rb:282:in
`run'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/../lib/mongrel/configurator.rb:281:in
`each'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/../lib/mongrel/configurator.rb:281:in
`run'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/mongrel_rails:128:in
`run'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/../lib/mongrel/command.rb:212:in
`run'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/mongrel_rails:281
    /usr/bin/mongrel_rails:19:in `load'
    /usr/bin/mongrel_rails:19

Rendering
/usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/templates/rescues/layout.erb
(internal_server_error)
Sniper A. (Guest)
on 2008-10-14 16:47
Kiki Kiki wrote:
> hallo, everyone
> (internal_server_error)

hai kiki
could you post that coding part here ?
it may be helpful
Kiki K. (Guest)
on 2008-10-14 17:13
Pokkai D. 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 .
Kiki K. (Guest)
on 2008-10-14 17:18
Pokkai D. wrote:
> Kiki Kiki wrote:
>> hallo, everyone
>> (internal_server_error)
>
> hai kiki
> could you post that coding part here ?
> it may be helpful

because i have used moret times replace , and all workde before, don't
working now. so i think , maybe only something about  environment is
wrong, maybe. i don't know.
Kiki K. (Guest)
on 2008-10-14 20:21
and show in Firebug

<h1>

  ArgumentError



    in AccountsController#filtered_balances_for_a_month



</h1>

<pre>tried to create Proc object without a block</pre>

<p><code>RAILS_ROOT: /home/lihui/workspace/adva_cms/adva_cms</code></p>

<div id="traces">





    <a href="#"
onclick="document.getElementById('Framework-Trace').style.display='none';document.getElementById

('Full-Trace').style.display='none';document.getElementById('Application-Trace').style.display='block'

;; return false;">Application Trace</a> |





    <a href="#"
onclick="document.getElementById('Application-Trace').style.display='none';document.getElementById

('Full-Trace').style.display='none';document.getElementById('Framework-Trace').style.display='block'

;; return false;">Framework Trace</a> |





    <a href="#"
onclick="document.getElementById('Application-Trace').style.display='none';document.getElementById

('Framework-Trace').style.display='none';document.getElementById('Full-Trace').style.display='block'

;; return false;">Full Trace</a>





    <div id="Application-Trace" style="display: block;">
This topic is locked and can not be replied to.