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

Warning: method status already defined #5316

Closed
louffoster opened this issue Jan 12, 2018 · 26 comments
Closed

Warning: method status already defined #5316

louffoster opened this issue Jan 12, 2018 · 26 comments

Comments

@louffoster
Copy link

Just upgraded to version 1.2.1 and now constantly get this warning message:

Warning: method status already defined

No idea what is causing it.

Running rails 5.1.4, Ruby 2.4.1

@joshmn
Copy link

joshmn commented Jan 20, 2018

Can you provide a stacktrace?

@jstumbaugh
Copy link
Contributor

I am seeing the same warning, but for a different method. This also happened when I upgraded to v1.2.1. It looks like this commit was added to warn about redefining a controller method.

In my instance, we added the method to override the default controller's method. Maybe we could add a way to silence the message?

@louffoster
Copy link
Author

Sorry for the delay; I was pulled to other projects. Back to this now.

There are no stack traces to show as it doesn't generate an exception. Simply a warning in the logs. Since version 1.3.0, when this shows up, the performance of the site is so slow such that it is unusable. Any suggestions would be great.

An example from the dev logs; note the long delay in response and the warning interspersed in the logs. This type of request should be a few seconds. I killed the server after 30 or so. Side note; the config as asset logs OFF, yet they show up anyway. I've raised a separate bug for this

Completed 200 OK in 891ms (Views: 413.8ms | ActiveRecord: 464.7ms)


::1 - - [14/Jun/2018:11:24:24 EDT] "GET /admin/sirsi_metadata?utf8=%E2%9C%93&q%5Buse_right_id_eq%5D=1&commit=Filter&order=id_desc HTTP/1.1" 200 84928
http://localhost:3000/ -> /admin/sirsi_metadata?utf8=%E2%9C%93&q%5Buse_right_id_eq%5D=1&commit=Filter&order=id_desc
Warning: method `status` already defined
::1 - - [14/Jun/2018:11:24:30 EDT] "GET /assets/active_admin-b62bb5ce009bced6cc48e6139ea1a4a27345b3fb442e0b7b8e3748985b8d0d6c.css HTTP/1.1" 200 291474
http://localhost:3000/admin/sirsi_metadata?utf8=%E2%9C%93&q%5Buse_right_id_eq%5D=1&commit=Filter&order=id_desc -> /assets/active_admin-b62bb5ce009bced6cc48e6139ea1a4a27345b3fb442e0b7b8e3748985b8d0d6c.css
Warning: method `status` already defined
::1 - - [14/Jun/2018:11:24:30 EDT] "GET /assets/active_admin/print-5dc667ee34a14c8bc2c0062f508a9d58055e32b7878fba9b761bb1ceebda06cb.css HTTP/1.1" 200 31065
http://localhost:3000/admin/sirsi_metadata?utf8=%E2%9C%93&q%5Buse_right_id_eq%5D=1&commit=Filter&order=id_desc -> /assets/active_admin/print-5dc667ee34a14c8bc2c0062f508a9d58055e32b7878fba9b761bb1ceebda06cb.css
Warning: method `status` already defined
::1 - - [14/Jun/2018:11:24:30 EDT] "GET /assets/active_admin-d748dbd582d1b80294b87659aa2eb1e85c47c42e902e89711524040e49d98c4a.js HTTP/1.1" 200 1276012
http://localhost:3000/admin/sirsi_metadata?utf8=%E2%9C%93&q%5Buse_right_id_eq%5D=1&commit=Filter&order=id_desc -> /assets/active_admin-d748dbd582d1b80294b87659aa2eb1e85c47c42e902e89711524040e49d98c4a.js
Warning: method `status` already defined
::1 - - [14/Jun/2018:11:24:45 EDT] "GET /assets/active_admin/orderable-29374dbb55b0012d78a37c614d573bb3474f0779849b478a147d0f1845ca6617.png HTTP/1.1" 200 220
http://localhost:3000/assets/active_admin-b62bb5ce009bced6cc48e6139ea1a4a27345b3fb442e0b7b8e3748985b8d0d6c.css -> /assets/active_admin/orderable-29374dbb55b0012d78a37c614d573bb3474f0779849b478a147d0f1845ca6617.png
::1 - - [14/Jun/2018:11:24:45 EDT] "GET /assets/active_admin/nested_menu_arrow_dark-7c43b8e0a5f8823875f49a093c9d7a6b374f885b6f9cc248ae9cd7e6e9b29034.gif HTTP/1.1" 200 0
http://localhost:3000/assets/active_admin-b62bb5ce009bced6cc48e6139ea1a4a27345b3fb442e0b7b8e3748985b8d0d6c.css -> /assets/active_admin/nested_menu_arrow_dark-7c43b8e0a5f8823875f49a093c9d7a6b374f885b6f9cc248ae9cd7e6e9b29034.gif
::1 - - [14/Jun/2018:11:24:45 EDT] "GET /assets/active_admin/nested_menu_arrow-15084d93c65c1964d7077700ea748bd2d70cfa2d4c19707c58a9c64e232dd442.gif HTTP/1.1" 200 0
http://localhost:3000/assets/active_admin-b62bb5ce009bced6cc48e6139ea1a4a27345b3fb442e0b7b8e3748985b8d0d6c.css -> /assets/active_admin/nested_menu_arrow-15084d93c65c1964d7077700ea748bd2d70cfa2d4c19707c58a9c64e232dd442.gif
::1 - - [14/Jun/2018:11:24:45 EDT] "GET /assets/message-8ad7ed94a6d63b35ed75318f9b1344646a97be1335d004354546d56f2541a139.png HTTP/1.1" 200 0

@louffoster
Copy link
Author

Another note; this message shows up when I start a console and initially start up the server. It almost seems like the server is being restarted over and over again when the performance goes bad.

@MikeRogers0
Copy link
Contributor

MikeRogers0 commented Jun 16, 2018

I've noticed the warning Warning: method restore_resource already defined also (only in my production environment, not local).

My app/admin/account.rb looks like:

ActiveAdmin.register Account do
  actions :show, :index

  action_item :restore_link, only: [:show] do
    if resource.deleted?
      link_to 'Restore account', restore_resource_admin_account_path(resource), method: :patch, 'data-confirm': 'Are you sure?'
  end

  member_action :restore_resource, method: :patch do
    resource.restore!
    redirect_to resource_path, notice: 'Account restored!'
  end
end

However, I also see two "Restore Account" buttons in on my show page. I'll try to setup an environment recreating this issue to help debug :)

Edit:

I was able to remove this warning & fix my duplicate button problem by changing my production configuration to be :

Rails.application.configure do
  # Don't eager load code, it's loading ActiveAdmin twice.
  config.eager_load = false
end

@varyonic
Copy link
Contributor

varyonic commented Jun 18, 2018

A useful tool for finding prior method definitions is pry, eg.

[1] pry(main)> cd UsersController
[2] pry(UsersController):1> show-source status

From: /usr/local/rvm/gems/ruby-2.3.5/gems/actionpack-5.2.0/lib/action_controller/metal.rb @ line 150:
Owner: ActionController::Metal
Visibility: public
Number of lines: 2

delegate :headers, :status=, :location=, :content_type=,
         :status, :location, :content_type, to: "@_response"

Overriding ActionController::Metal seems unwise. This warning was introduced exactly because users were confused by the results when silently overwriting Rails controller methods.

If you are deliberately and knowingly overriding an existing method you can use undef first as discussed in #5347

@louffoster
Copy link
Author

Here is what I get when I launch a console in my project:

lf6f$ rails c
Warning: method `status` already defined
Warning: method `status` already defined
Running via Spring preloader in process 64584
Loading development environment (Rails 5.2.0)
[1] pry(main)> show-source status
Error: Couldn't locate a definition for status

Similar results if I break in a controller and try to find the definition.

@varyonic
Copy link
Contributor

TL;DR rename your member_action away from status and see if that resolves some of your issues.

@MikeRogers0
Copy link
Contributor

I managed to recreated the same error in a blank rails project ( https://github.com/MikeRogers0/ActiveAdminDefinedMethodDemo ) - @louffoster Would I be right to say you're using multiple engines in your app?

@louffoster
Copy link
Author

Sorry, no. It is a very old project, and I think it had some before I inherited it a few years ago, but not now. It is in a public repo here: https://github.com/uvalib/tracksys

@jeffblake
Copy link

jeffblake commented Sep 25, 2018

I am getting a lot of these as well, when starting the server and loading the console. For example this resource

ActiveAdmin.register User do

  includes :guest

  filter :id
  filter :name
  filter :email

  index do
    id_column
    column :name
    column :email
    actions do |user|
      item t(:login), login_admin_user_path(user), class: 'member_link'
    end
  end

  member_action :login, method: :get do
    request.env['warden'].request.env['devise.skip_trackable'] = '1'
    sign_in_and_redirect :user, resource
  end

  form do |f|
    inputs do
      input :email
      input :password
      input :time_zone
    end
    actions
  end

end

triggers

Warning: method `login` already defined

Using latest rails version, bootsnap, etc.

@matssigge
Copy link

I'm also getting this for several "login" actions. Changing to "log_in" gets rid of them when running the rails server, but when running my specs, I still get one instance of "method 'log_in' already defined". Also, I get the same message for three other member_actions, and they are definitely not colliding with anything defined somewhere else - the names are unique to the app and to one admin resource.

Latest rails (5.2.1) and bootsnap.

@MikeRogers0
Copy link
Contributor

Just something I noticed while trying to find a fix in https://github.com/MikeRogers0/ActiveAdminDefinedMethodDemo

If I add puts "I'm being evaluated I think" into app/admin/projects.rb, then run RACK_ENV=production RAILS_ENV=production bx rails c, I get the output:

I'm being evaluated I think
I'm being evaluated I think
Warning: method `restore_resource` already defined
Loading production environment (Rails 5.2.0)

I think perhaps config.cache_classes = true in config/environments/production.rb is causing the app/admin/* folder to be loaded twice. @varyonic what's the best way to make it so it won't register a resource a second time?

@MikeRogers0
Copy link
Contributor

MikeRogers0 commented Nov 1, 2018

Good news, I found a way to fix this I think 😊

Move your folder app/admin to lib/admin, then in your config/initializers/active_admin.rb file add:

# == Load Paths
#
# If you're noticing a warning in your logs/console like:
# "Warning: method `restore_resource` already defined"
# Move your `app/admin` folder into `lib/admin`
# Then manually add the load path like:
config.load_paths += Dir[Rails.root.join('lib', 'admin')]

@bdezonia
Copy link

bdezonia commented Nov 6, 2018

MikeRogers0,

I get initialization errors during load if I do this. I am on rails 5.1.6.

@MikeRogers0
Copy link
Contributor

@bdezonia What initialization errors are you seeing?

@bdezonia
Copy link

bdezonia commented Nov 7, 2018

@MikeRogers0

Here is the beginning of a stack trace:

DOM10300:reggie_rails bdezonia$ rails s
=> Booting Puma
=> Rails 5.1.6 application starting in development
=> Run rails server -h for more startup options
Exiting
/Users/bdezonia/.rvm/gems/ruby-2.3.8@reggie_rails/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:512:in load_missing_constant': Unable to autoload constant Admin::Contact, expected /Users/bdezonia/workspaces/railsapps/reggie_rails/lib/admin/contact.rb to define it (LoadError) from /Users/bdezonia/.rvm/gems/ruby-2.3.8@reggie_rails/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:202:in const_missing'

lib/admin/contact.rb exists and is organized like such:

ActiveAdmin.register Contact do

much much stuff

end

Let me know if you need more info. Thanks.

@MikeRogers0
Copy link
Contributor

@bdezonia What is defined in lib/admin/contact.rb?

@bdezonia
Copy link

bdezonia commented Dec 4, 2018

Filters, batch actions, collection_actions, controller methods, and a form. Over 350 lines; I don't really want to post it.

@MikeRogers0
Copy link
Contributor

@bdezonia Is the register something like:

ActiveAdmin.register Admin::Contact do

or

ActiveAdmin.register Contact do

? Reason I ask is because the error message reads:
load_missing_constant': Unable to autoload constant Admin::Contact, expected /Users/bdezonia/workspaces/railsapps/reggie_rails/lib/admin/contact.rb to define it (LoadError) which looks to be putting a Contact object in the Admin namespace, which might help me debug what's up.

Also if you'd prefer to share privately, I'm super eager to help debug to confirm what's up with my fix :)

@bdezonia
Copy link

bdezonia commented Dec 5, 2018

It's like this:

ActiveAdmin.register Contact do

I have shared the code with you privately.

@deivid-rodriguez
Copy link
Member

Thanks so much @MikeRogers0 for helping out here!

It'd be great if we could somehow get a platform independent reproduction via docker. I tried your reproduction application and I couldn't reproduce it... 😞.

@MikeRogers0
Copy link
Contributor

@deivid-rodriguez Did you checkout from MikeRogers0-YouTube/ActiveAdminDefinedMethodDemo@77cace4 - this commit?

@deivid-rodriguez
Copy link
Member

Not really 🤣, that explains everything. I'll have a look again!

@disambiguator
Copy link

disambiguator commented Jul 24, 2019

Hi! Any update on this issue? I am also seeing this error whenever using member_action or collection_action on an AA model to override a default action, like :create, :read, :update, :destroy.

Edit: I solved this by replacing any

member_action :destroy, method: :delete do...end

with

controller do
    def destroy
    ...
    end
end

@scarroll32
Copy link

scarroll32 commented Dec 8, 2019

I can confirm that this causes a warning:

 member_action :reset_user_password do
    user = User.find(params[:id])
    user.send_reset_password_instructions
    redirect_to(admin_user_path(user),
                notice: "Password reset email sent to #{user.email}")
 end

While this does not:

controller do
    def reset_user_password
      user = User.find(params[:id])
      user.send_reset_password_instructions
      redirect_to(admin_user_path(user),
                  notice: "Password reset email sent to #{user.email}")
    end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests