Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrong number of arguments on add_flash_types for version 5.0.0 #791

Closed
wbotelhos opened this issue May 3, 2016 · 6 comments
Closed

wrong number of arguments on add_flash_types for version 5.0.0 #791

wbotelhos opened this issue May 3, 2016 · 6 comments
Milestone

Comments

@wbotelhos
Copy link

Updating from paper_trail 4.1.0 to 5.0.0, it raises error on my flash register:

add_flash_types :error, :info, :warn

If I comment it, the error goes way. Currently I'm not using the paper trail, I just have it on my Gemfile.

2016-05-03T18:52:25] INFO  Rails : method=GET path=/dashboards format=html controller=dashboards action=index status=500 error='ArgumentError: wrong number of arguments (given 1, expected 0)' duration=2243.03 view=2045.70 db=19.84
[2016-05-03T18:52:25] FATAL Rails : 
ArgumentError (wrong number of arguments (given 1, expected 0)):
  actionpack (4.2.6) lib/action_controller/metal/flash.rb:35:in `block (2 levels) in add_flash_types'
  paper_trail (5.0.0) lib/paper_trail/frameworks/rails/controller.rb:97:in `warn_about_not_setting_whodunnit'
  activesupport (4.2.6) lib/active_support/callbacks.rb:432:in `block in make_lambda'
  activesupport (4.2.6) lib/active_support/callbacks.rb:239:in `block in halting'
  activesupport (4.2.6) lib/active_support/callbacks.rb:506:in `block in call'
  activesupport (4.2.6) lib/active_support/callbacks.rb:506:in `each'
  activesupport (4.2.6) lib/active_support/callbacks.rb:506:in `call'
  activesupport (4.2.6) lib/active_support/callbacks.rb:92:in `__run_callbacks__'
  activesupport (4.2.6) lib/active_support/callbacks.rb:778:in `_run_process_action_callbacks'
  activesupport (4.2.6) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (4.2.6) lib/abstract_controller/callbacks.rb:19:in `process_action'
  actionpack (4.2.6) lib/action_controller/metal/rescue.rb:29:in `process_action'
  actionpack (4.2.6) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
  activesupport (4.2.6) lib/active_support/notifications.rb:164:in `block in instrument'
  activesupport (4.2.6) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (4.2.6) lib/active_support/notifications.rb:164:in `instrument'
  actionpack (4.2.6) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
  actionpack (4.2.6) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
  activerecord (4.2.6) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
  actionpack (4.2.6) lib/abstract_controller/base.rb:137:in `process'
  actionview (4.2.6) lib/action_view/rendering.rb:30:in `process'
  actionpack (4.2.6) lib/action_controller/metal.rb:196:in `dispatch'
  actionpack (4.2.6) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
  actionpack (4.2.6) lib/action_controller/metal.rb:237:in `block in action'
  actionpack (4.2.6) lib/action_dispatch/routing/route_set.rb:74:in `dispatch'
  actionpack (4.2.6) lib/action_dispatch/routing/route_set.rb:43:in `serve'
  actionpack (4.2.6) lib/action_dispatch/journey/router.rb:43:in `block in serve'
  actionpack (4.2.6) lib/action_dispatch/journey/router.rb:30:in `each'
  actionpack (4.2.6) lib/action_dispatch/journey/router.rb:30:in `serve'
  actionpack (4.2.6) lib/action_dispatch/routing/route_set.rb:817:in `call'
  bullet (5.0.0) lib/bullet/rack.rb:12:in `call'
  i18n-js (2.1.2) lib/i18n-js/middleware.rb:11:in `call'
  warden (1.2.6) lib/warden/manager.rb:35:in `block in call'
  warden (1.2.6) lib/warden/manager.rb:34:in `catch'
  warden (1.2.6) lib/warden/manager.rb:34:in `call'
  rack (1.6.4) lib/rack/etag.rb:24:in `call'
  rack (1.6.4) lib/rack/conditionalget.rb:25:in `call'
  rack (1.6.4) lib/rack/head.rb:13:in `call'
  actionpack (4.2.6) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
  actionpack (4.2.6) lib/action_dispatch/middleware/flash.rb:260:in `call'
  rack (1.6.4) lib/rack/session/abstract/id.rb:225:in `context'
  rack (1.6.4) lib/rack/session/abstract/id.rb:220:in `call'
  actionpack (4.2.6) lib/action_dispatch/middleware/cookies.rb:560:in `call'
  activerecord (4.2.6) lib/active_record/query_cache.rb:36:in `call'
  activerecord (4.2.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:653:in `call'
  activerecord (4.2.6) lib/active_record/migration.rb:377:in `call'
  actionpack (4.2.6) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
  activesupport (4.2.6) lib/active_support/callbacks.rb:88:in `__run_callbacks__'
  activesupport (4.2.6) lib/active_support/callbacks.rb:778:in `_run_call_callbacks'
  activesupport (4.2.6) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (4.2.6) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (4.2.6) lib/action_dispatch/middleware/reloader.rb:73:in `call'
  actionpack (4.2.6) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
  actionpack (4.2.6) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
  actionpack (4.2.6) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  lograge (0.3.6) lib/lograge/rails_ext/rack/logger.rb:15:in `call_app'
  railties (4.2.6) lib/rails/rack/logger.rb:22:in `call'
  quiet_assets (1.1.0) lib/quiet_assets.rb:27:in `call_with_quiet_assets'
  request_store (1.3.1) lib/request_store/middleware.rb:9:in `call'
  actionpack (4.2.6) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
  rack (1.6.4) lib/rack/runtime.rb:18:in `call'
  activesupport (4.2.6) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
  rack (1.6.4) lib/rack/lock.rb:17:in `call'
  actionpack (4.2.6) lib/action_dispatch/middleware/static.rb:120:in `call'
  rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
  railties (4.2.6) lib/rails/engine.rb:518:in `call'
  railties (4.2.6) lib/rails/application.rb:165:in `call'
  rack (1.6.4) lib/rack/content_length.rb:15:in `call'
  thin (1.6.4) lib/thin/connection.rb:86:in `block in pre_process'
  thin (1.6.4) lib/thin/connection.rb:84:in `catch'
  thin (1.6.4) lib/thin/connection.rb:84:in `pre_process'
  thin (1.6.4) lib/thin/connection.rb:53:in `process'
  thin (1.6.4) lib/thin/connection.rb:39:in `receive_data'
  eventmachine (1.2.0.1) lib/eventmachine.rb:194:in `run_machine'
  eventmachine (1.2.0.1) lib/eventmachine.rb:194:in `run'
  thin (1.6.4) lib/thin/backends/base.rb:73:in `start'
  thin (1.6.4) lib/thin/server.rb:162:in `start'
  rack (1.6.4) lib/rack/handler/thin.rb:19:in `run'
  rack (1.6.4) lib/rack/server.rb:286:in `start'
  railties (4.2.6) lib/rails/commands/server.rb:80:in `start'
  railties (4.2.6) lib/rails/commands/commands_tasks.rb:80:in `block in server'
  railties (4.2.6) lib/rails/commands/commands_tasks.rb:75:in `tap'
  railties (4.2.6) lib/rails/commands/commands_tasks.rb:75:in `server'
  railties (4.2.6) lib/rails/commands/commands_tasks.rb:39:in `run_command!'
  railties (4.2.6) lib/rails/commands.rb:17:in `<top (required)>'
  bin/rails:9:in `require'
  bin/rails:9:in `<top (required)>'
  spring (1.7.1) lib/spring/client/rails.rb:28:in `load'
  spring (1.7.1) lib/spring/client/rails.rb:28:in `call'
  spring (1.7.1) lib/spring/client/command.rb:7:in `call'
  spring (1.7.1) lib/spring/client.rb:30:in `run'
  spring (1.7.1) bin/spring:49:in `<top (required)>'
  spring (1.7.1) lib/spring/binstub.rb:11:in `load'
  spring (1.7.1) lib/spring/binstub.rb:11:in `<top (required)>'
  bin/spring:13:in `require'
  bin/spring:13:in `<top (required)>'
  bin/rails:3:in `load'
  bin/rails:3:in `<main>'
@jaredbeck
Copy link
Member

Does add_flash_types :warn define a warn method, perhaps?

@jaredbeck
Copy link
Member

Does add_flash_types :warn define a warn method, perhaps?

Yeah, it does. So, I don't recommend using the name "warn" for a flash type. In my mind, it's as if you defined a new method named "puts", and then were surprised when puts no longer works :)

That said, PT could use an explicit receiver, e.g. Kernel.warn, or $stderr.puts.

jaredbeck added a commit that referenced this issue May 4, 2016
Some people override warn in their applications. Using an explicit
receiver protects against this.

[Fixes #791]
jaredbeck added a commit that referenced this issue May 4, 2016
Some people override warn in their applications. Using an explicit
receiver protects against this.

[Fixes #791]
@jaredbeck jaredbeck added this to the 5.0.1 milestone May 4, 2016
@jaredbeck
Copy link
Member

Closed by #793, but please reconsider overriding the warn method. You're likely to have trouble with other gems.

@batter
Copy link
Collaborator

batter commented May 4, 2016

👍

@wbotelhos
Copy link
Author

@jaredbeck I'm surprised that Rails 4 creates a method via add_flash_types, I did not know that.

Thanks for the tip and the quickly fix. (:

@jaredbeck
Copy link
Member

jaredbeck commented May 4, 2016

Rails loves to create methods at runtime :) When you call has_many, for example, it defines between 5 and 16 methods, depending on how you count them.

    collection(force_reload = false)
    collection<<(object, ...)
    collection.delete(object, ...)
    collection.destroy(object, ...)
    collection=(objects)
    collection_singular_ids
    collection_singular_ids=(ids)
    collection.clear
    collection.empty?
    collection.size
    collection.find(...)
    collection.where(...)
    collection.exists?(...)
    collection.build(attributes = {}, ...)
    collection.create(attributes = {})
    collection.create!(attributes = {})

http://guides.rubyonrails.org/association_basics.html#has-many-association-reference

devonestes pushed a commit to devonestes/paper_trail that referenced this issue May 9, 2016
Some people override warn in their applications. Using an explicit
receiver protects against this.

[Fixes paper-trail-gem#791]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants