Closed SirNerdBear closed 8 years ago
+1
+1
+1
@SirNerdBear If you fix the version constraint, does everything else work as expected in a Rails 5 app?
+1
+1
Forked and removed the <5 dependency. Here is the output:
/Users/nicklandgrebe/.rvm/gems/ruby-2.2.2/gems/activerecord-5.0.0/lib/active_record/relation.rb:18:in `<class:Relation>': uninitialized constant ActiveRecord::Relation::QueryMethods (NameError)
from /Users/nicklandgrebe/.rvm/gems/ruby-2.2.2/gems/activerecord-5.0.0/lib/active_record/relation.rb:5:in `<module:ActiveRecord>'
from /Users/nicklandgrebe/.rvm/gems/ruby-2.2.2/gems/activerecord-5.0.0/lib/active_record/relation.rb:3:in `<top (required)>'
from /Users/nicklandgrebe/.rvm/gems/ruby-2.2.2/gems/activerecord-5.0.0/lib/active_record/relation/from_clause.rb:2:in `<module:ActiveRecord>'
from /Users/nicklandgrebe/.rvm/gems/ruby-2.2.2/gems/activerecord-5.0.0/lib/active_record/relation/from_clause.rb:1:in `<top (required)>'
from /Users/nicklandgrebe/.rvm/gems/ruby-2.2.2/gems/activerecord-5.0.0/lib/active_record/relation/query_methods.rb:1:in `<top (required)>'
from /Users/nicklandgrebe/.rvm/gems/ruby-2.2.2/bundler/gems/active_record-acts_as-cc9b2e706a3c/lib/active_record/acts_as/querying.rb:3:in `<module:ActiveRecord>'
from /Users/nicklandgrebe/.rvm/gems/ruby-2.2.2/bundler/gems/active_record-acts_as-cc9b2e706a3c/lib/active_record/acts_as/querying.rb:2:in `<top (required)>'
from /Users/nicklandgrebe/.rvm/gems/ruby-2.2.2/bundler/gems/active_record-acts_as-cc9b2e706a3c/lib/active_record/acts_as.rb:8:in `<top (required)>'
from /Users/nicklandgrebe/.rvm/gems/ruby-2.2.2/gems/bundler-1.12.5/lib/bundler/runtime.rb:100:in `require'
from /Users/nicklandgrebe/.rvm/gems/ruby-2.2.2/gems/bundler-1.12.5/lib/bundler/runtime.rb:100:in `rescue in block in require'
from /Users/nicklandgrebe/.rvm/gems/ruby-2.2.2/gems/bundler-1.12.5/lib/bundler/runtime.rb:77:in `block in require'
from /Users/nicklandgrebe/.rvm/gems/ruby-2.2.2/gems/bundler-1.12.5/lib/bundler/runtime.rb:70:in `each'
from /Users/nicklandgrebe/.rvm/gems/ruby-2.2.2/gems/bundler-1.12.5/lib/bundler/runtime.rb:70:in `require'
from /Users/nicklandgrebe/.rvm/gems/ruby-2.2.2/gems/bundler-1.12.5/lib/bundler.rb:102:in `require'
from /Users/nicklandgrebe/dev/humanityrising/config/application.rb:7:in `<top (required)>'
from /Users/nicklandgrebe/.rvm/gems/ruby-2.2.2/gems/railties-5.0.0/lib/rails/commands/commands_tasks.rb:156:in `require'
from /Users/nicklandgrebe/.rvm/gems/ruby-2.2.2/gems/railties-5.0.0/lib/rails/commands/commands_tasks.rb:156:in `require_application_and_environment!'
from /Users/nicklandgrebe/.rvm/gems/ruby-2.2.2/gems/railties-5.0.0/lib/rails/commands/commands_tasks.rb:143:in `generate_or_destroy'
from /Users/nicklandgrebe/.rvm/gems/ruby-2.2.2/gems/railties-5.0.0/lib/rails/commands/commands_tasks.rb:60:in `generate'
from /Users/nicklandgrebe/.rvm/gems/ruby-2.2.2/gems/railties-5.0.0/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
from /Users/nicklandgrebe/.rvm/gems/ruby-2.2.2/gems/railties-5.0.0/lib/rails/commands.rb:18:in `<top (required)>'
from bin/rails:8:in `require'
from bin/rails:8:in `<main>'
Appears that active_record/acts_as/querying.rb
does something to the autoloading of QueryMethods
in ActiveRecord::Relation
so that it is expected to be ActiveRecord::Relation::QueryMethods
instead of just ActiveRecord::QueryMethods
: https://github.com/rails/rails/blob/master/activerecord/lib/active_record/relation.rb#L16
I know that because if I remove QueryMethods
module from active_record/acts_as/querying.rb
there are no errors.
Any ideas on how to fix this? Module loading is not my forte.
I just added a pull request for those looking to use this with Rails 5.
You can also use https://github.com/nicklandgrebe/active_record-acts_as in the meantime.
i am having issues with getting this to work with rails 5. the associations on the base model are loaded but the associations on the child model are not causing the _accepts_nested_attributesfor to not find the association.
Are you using the latest version released with #80 ? Can you please provide code as to what you mean in regards to "base model" and "child model"?
In that pull request, _reflections
was updated for Rails 5 and correctly loads all and that was the only association-related code this gem touches.
I have models that look like this:
class BaseUser < ApplicationRecord
actable as: :user, class_name: 'BaseUser'
has_many :bars
end
class FooUser < ApplicationRecord
acts_as :base_user, as: :user, class_name: 'BaseUser'
has_many :foos
accepts_nested_attributes_for :foos
end
the bars assoication was loaded but not the foos relationship. I solved it by moving the _actsas below the associations like:
class FooUser < ApplicationRecord
has_many :foos
accepts_nested_attributes_for :foos
acts_as :base_user, as: :user, class_name: 'BaseUser'
end
Since the gem is using a pessimistic version constraint for ActiveRecord, this gem doesn't work with Rails 5.