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

NoMethodError: undefined method `acts_as_list' #303

Closed
oyeanuj opened this issue Feb 28, 2018 · 14 comments
Closed

NoMethodError: undefined method `acts_as_list' #303

oyeanuj opened this issue Feb 28, 2018 · 14 comments

Comments

@oyeanuj
Copy link

oyeanuj commented Feb 28, 2018

Hey @brendon, I ran into an issue which feels awkwardly similar to #176 but the solution mentioned there doesn't seem to work for me.

I am on Rails 5.1.4 (API-only mode), and did the following as per the README:

  1. Added it to Gemfile and installed the gem.
  2. Created a column for the position in the intended model.
  3. Added the following code snippet.
  belongs_to		:member
    validates 		:member,
    presence: 		true

  acts_as_list		scope:	:member
  1. And got the following error:
[100] pry(main)> Movie
NoMethodError: undefined method `acts_as_list' for #<Class:0x00007f9b373ca6c0>
Did you mean?  acts_like?
from /Users/anuj/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/activerecord-5.1.4/lib/active_record/dynamic_matchers.rb:22:in `method_missing'

I assume I am missing some obvious step, but can't seem to figure out what that might be. I went through #176, and the solution mentioned there to include include ActiveRecord::Acts::List throws a different kind of error for me.

Any thoughts on what might be going on are super appreciated?

@brendon
Copy link
Owner

brendon commented Feb 28, 2018

Hi @oyeanuj, it definitely looks like acts_as_list isn't being required for some reason (or at least the acts_as_list method isn't being added to ActiveRecord::Base.

The class methods are added via this:

https://github.com/swanandp/acts_as_list/blob/master/lib/acts_as_list/active_record/acts/active_record.rb

So if active_record isn't loading then perhaps that's the problem. Since you're restricting what parts of Rails are loaded, can you double check that you're indeed loading ActiveRecord? and doing it the right way? :)

@oyeanuj
Copy link
Author

oyeanuj commented Feb 28, 2018

@brendon Thanks for the quick response! That makes sense but I am not sure why that might be happening since I've tested it with a clean Rails-API mode which includes ActiveRecord (I use it everywhere!)

Here is my config/application.rb if that helps: https://gist.github.com/oyeanuj/6b6db7f6b239c00f6039883bb3969919

@brendon
Copy link
Owner

brendon commented Feb 28, 2018

Thanks @oyeanuj :) It doesn't look like you're loading in active_support though I can't be sure. Perhaps that's always loaded anyway? If it's not, that might be the reason why the on_load callback isn't being called and thus aal isn't loading. Can you do some investigation down that track? Perhaps you only need to include a small part of active support to do with loading?

@oyeanuj
Copy link
Author

oyeanuj commented Feb 28, 2018

So, it seems like ActiveSupport.onLoad is being called. In one of the initializer files, I added the following code which got printed:

ActiveSupport.on_load(:active_record) do
 ap "Please work"
end

In general, FWIW, here is the list of middleware that an API-app comes with, by default: http://edgeguides.rubyonrails.org/api_app.html#choosing-middleware

Any ideas on what might be going on, given all of this?

Appreciate you taking the time to figure this out!

@brendon
Copy link
Owner

brendon commented Feb 28, 2018

No worries :)

In that case what I'd do next is clone a local copy of acts_as_list and update your gem file to refer to that. Then you can start playing around with how the gem is loaded to see if you can figure out where it's going wrong. Try adding a logging line in our on_load callback to see if that logs anything etc...

It could be that we're initialising incorrectly somehow but hard to say :D

@bevinh
Copy link

bevinh commented Apr 26, 2018

Not working for me either. Did you find a fix @oyeanuj?

@brendon
Copy link
Owner

brendon commented Apr 26, 2018

Hi @bevinh, can you try the suggestion in my last comment? You need to pinpoint the loading sequence problem so we can figure out a way around it.

@oyeanuj
Copy link
Author

oyeanuj commented Apr 27, 2018

@brendon @bevinh I haven't had a chance to go back to this but I am hoping to do this soon.

@bevinh If you are able to test out the suggestion above sooner, that would be great!

@bevinh
Copy link

bevinh commented Apr 27, 2018

I've just noticed that it works if it's scoped (e.g. acts_as_list scope: :list) but does not if it isn't. I was using an example from GoRails where the main list was just used with acts_as_list (no scope). I'm not sure what the intention of not scoping it is in that tutorial. I haven't had a chance to dig much deeper, as I'm working on a different app right now, but hopefully that is helpful. Did something change that requires the scope?

@brendon
Copy link
Owner

brendon commented Apr 27, 2018

Lol, I've never known it not to require a scope :) I suppose it doesn't need one though. I'm not even sure there's tests for that... Might be something to investigate if you have the time :)

@oyeanuj
Copy link
Author

oyeanuj commented Jul 28, 2018

@brendon Sorry for the delay here. So, to your question about ActiveSupport, it is being loaded:

[8] pry(main)> defined?(ActiveSupport.on_load)
=> "method"

It doesn't seem like API-only apps do anything to ActiveSupport

Thoughts on what else might be going on? Anything related to @bevinh's comment above?

@brendon
Copy link
Owner

brendon commented Jul 29, 2018

The only idea I have is to build a new empty (full) rails app. Then confirm it works with acts_as_list. Next start stripping off the bits you don't need and check if it works as you remove each bit. That should at least help you isolate the problem.

Let me know how you get on.

@oyeanuj
Copy link
Author

oyeanuj commented Aug 10, 2018

It worked once I upgraded to Rails 5.2 ¯_(ツ)_/¯

Thanks for your help!

@oyeanuj oyeanuj closed this as completed Aug 10, 2018
@brendon
Copy link
Owner

brendon commented Aug 11, 2018

SO weird! :D Glad you got it to work :)

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