Rails flash抛出错误数量的参数(0表示2)错误

时间:2022-06-24 23:14:12

I just upgraded an app from rails 1.2.3 to rails 2.0.2 (I tried 2.3.2 first and failed). I had to make a few plugin tweaks, but overall went smoothly. That is, until I realized my flashes weren't working. So I then downgraded back to 1.2.3, and still receive the following error:

我刚刚将应用程序从rails 1.2.3升级到rails 2.0.2(我先尝试过2.3.2但失败了)。我不得不做一些插件调整,但整体进展顺利。也就是说,直到我意识到我的闪光灯没有工作。所以我然后降级回1.2.3,仍然收到以下错误:

ActionView::TemplateError (wrong number of arguments (0 for 2))

Coming from wherever I first call flash in a view

来自我在视图中第一次调用flash的地方

<%= render :partial => "flash_msg", :object => flash %>

The flash_msg template is:

flash_msg模板是:

<% if flash[:notice] %>
    <div class="notice"><%= flash[:notice] %></div>
<% elsif flash[:warning] %>
    <div class="warning"><%= flash[:warning] %></div>
<% end %>

The full trace is:

完整的痕迹是:

ActionView::TemplateError (wrong number of arguments (0 for 2)) on line #53 of layouts/store.rhtml:
50: 
51:             <div class="col-left">
52:                 
53:                 <%= render :partial => "user/flash_msg", :object => flash %>
54:         
app/views/layouts/store.rhtml:53:in `flash'
app/views/layouts/store.rhtml:53:in `_run_erb_47app47views47layouts47store46rhtml'
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_view/base.rb:637:in `send'
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_view/base.rb:637:in `compile_and_render_template'
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_view/base.rb:365:in `render_template'
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_view/base.rb:316:in `render_file'
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/layout.rb:268:in `render_without_benchmark'
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/benchmarking.rb:51:in `render'
/opt/local/lib/ruby/1.8/benchmark.rb:293:in `measure'
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/benchmarking.rb:51:in `render'
app/controllers/store_controller.rb:75:in `browse'
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:1158:in `send'
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:1158:in `perform_action_without_filters'
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:697:in `call_filters'
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:689:in `perform_action_without_benchmark'
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
/opt/local/lib/ruby/1.8/benchmark.rb:293:in `measure'
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/rescue.rb:199:in `perform_action_without_caching'
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/caching.rb:678:in `perform_action'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/abstract/query_cache.rb:33:in `cache'
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/query_cache.rb:8:in `cache'
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/caching.rb:677:in `perform_action'
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:524:in `send'
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:524:in `process_without_filters'
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:685:in `process_without_session_management_support'
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/session_management.rb:123:in `process'
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:388:in `process'
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:171:in `handle_request'
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:115:in `dispatch'
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:126:in `dispatch_cgi'
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:9:in `dispatch'
/opt/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:78:in `process'
/opt/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:76:in `synchronize'
/opt/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:76:in `process'
/opt/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:618:in `process_client'
/opt/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:617:in `each'
/opt/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:617:in `process_client'
/opt/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `run'
/opt/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `initialize'
/opt/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `new'
/opt/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `run'
/opt/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in `initialize'
/opt/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in `new'
/opt/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in `run'
/opt/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:271:in `run'
/opt/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:270:in `each'
/opt/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:270:in `run'
/opt/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:127:in `run'
/opt/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/command.rb:211:in `run'
/opt/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:243
/opt/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load'
/opt/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load'
/opt/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
/opt/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load'
/opt/local/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/servers/mongrel.rb:64
/opt/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/opt/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
/opt/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
/opt/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
/opt/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
/opt/local/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/server.rb:39
/opt/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/opt/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
script/server:3

5 个解决方案

#1


One possibility is that something (or someone) may have defined a flash method which is overriding the default flash behaviour. I.e. somewhere a flash method is defined which does take 2 parameters and where you have flash[:notice] it is calling the flash method and failing.

一种可能性是某些(或某人)可能已经定义了一种覆盖默认闪存行为的闪存方法。即在某个地方定义了一个flash方法,它确实需要2个参数,并且你有flash [:notice]它正在调用flash方法并且失败。

#2


@Shadwell, you were absolutely correct! There was a view helper function named "flash" that rails 2+ does not like!

@Shadwell,你是绝对正确的!有一个名为“flash”的视图辅助函数,rails 2+不喜欢!

So I learned that a helper function named "flash" in Rails 1.2.3 will not override the flash hash. In Rails 2+ it will.

所以我了解到Rails 1.2.3中名为“flash”的辅助函数不会覆盖flash哈希。在Rails 2+中它会。

#3


Try to remove ":object => flash". I think your partial will have access to flash without passing it as :object.

尝试删除“:object => flash”。我认为你的部分将访问闪存而不传递它:object。

#4


I do that and the error just moves to the flash_msg partial:

我这样做,错误只是移动到flash_msg部分:

wrong number of arguments (0 for 2)

Extracted source (around line #1):

提取的来源(第1行):

1: <% if flash[:notice] %>
2:  <div class="notice"><%= flash[:notice] %></div>
3: <% elsif flash[:warning] %>
4:  <div class="warning"><%= flash[:warning] %></div>

#5


After some more research, I see that as soon as it renders the view, flash no longer works. For instance, flash.class throughout the controller returns:

经过一些研究后,我发现只要渲染视图,闪光灯就不再有效了。例如,整个控制器中的flash.class返回:

ActionController::Flash::FlashHash

But as soon as I try to get flash.class in a view, I get the same error above.

但是一旦我尝试在视图中获取flash.class,我就会得到同样的错误。

And if I do give it two arguments, it returns "String." For instance:

如果我给它两个参数,它将返回“String”。例如:

flash(nil, nil).class = String

That help anyone?

那有助于任何人?

#1


One possibility is that something (or someone) may have defined a flash method which is overriding the default flash behaviour. I.e. somewhere a flash method is defined which does take 2 parameters and where you have flash[:notice] it is calling the flash method and failing.

一种可能性是某些(或某人)可能已经定义了一种覆盖默认闪存行为的闪存方法。即在某个地方定义了一个flash方法,它确实需要2个参数,并且你有flash [:notice]它正在调用flash方法并且失败。

#2


@Shadwell, you were absolutely correct! There was a view helper function named "flash" that rails 2+ does not like!

@Shadwell,你是绝对正确的!有一个名为“flash”的视图辅助函数,rails 2+不喜欢!

So I learned that a helper function named "flash" in Rails 1.2.3 will not override the flash hash. In Rails 2+ it will.

所以我了解到Rails 1.2.3中名为“flash”的辅助函数不会覆盖flash哈希。在Rails 2+中它会。

#3


Try to remove ":object => flash". I think your partial will have access to flash without passing it as :object.

尝试删除“:object => flash”。我认为你的部分将访问闪存而不传递它:object。

#4


I do that and the error just moves to the flash_msg partial:

我这样做,错误只是移动到flash_msg部分:

wrong number of arguments (0 for 2)

Extracted source (around line #1):

提取的来源(第1行):

1: <% if flash[:notice] %>
2:  <div class="notice"><%= flash[:notice] %></div>
3: <% elsif flash[:warning] %>
4:  <div class="warning"><%= flash[:warning] %></div>

#5


After some more research, I see that as soon as it renders the view, flash no longer works. For instance, flash.class throughout the controller returns:

经过一些研究后,我发现只要渲染视图,闪光灯就不再有效了。例如,整个控制器中的flash.class返回:

ActionController::Flash::FlashHash

But as soon as I try to get flash.class in a view, I get the same error above.

但是一旦我尝试在视图中获取flash.class,我就会得到同样的错误。

And if I do give it two arguments, it returns "String." For instance:

如果我给它两个参数,它将返回“String”。例如:

flash(nil, nil).class = String

That help anyone?

那有助于任何人?