Closed noahsettersten closed 7 years ago
Here's the relevant portion of config/application.rb
:
require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
# require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "action_cable/railtie"
require "sprockets/railtie"
For now, I was able to work around this by creating a local vendor copy of the previous protected_attributes
code with a few minor modifications to play nice with Mongoid and Rails 5.
Maybe we can use a class_eval
or module_eval
instead of defining the module.
I am not familiar with non-activerecord especially mongoid. Can you provide the relevant upgrades for your local copy in a gist or something?
I can share those changes, but I'm not sure they'll be very helpful here. I'm not too familiar with the inner workings of ActiveModel and really the only changes I made to the original code was to swap some requires to use require_relative
for locating the correct code.
As for the differences with non-activerecord / mongoid, it seems that only the modules within the /lib/active_model
folder are applied and in use. Perhaps if the initial ActiveModel::Core.initialize was injected like so instead of defined in the main /lib/protected_attributes_continued.rb
:
require 'active_record/custom_initialize' if defined? ActiveRecord
Otherwise, our use is a pretty edge case overall (we've actually planned to re-architect some of this in the future). I wouldn't focus too much of your time if it isn't a simple change.
I just made a branch non_active_record
please try that and report your results for both with active_record and non-active_record
Thanks for the quick work!
non_active_record
branch, the server starts up successfully and I don't notice any issues in my quick review of the app.master
branch version, I get the following error on starting the server with bundle exec rails s
:
/Users/noah/.rvm/gems/ruby-2.3.2@conover-r5/gems/bundler-1.14.6/lib/bundler/runtime.rb:94:in `rescue in block (2 levels) in require': There was an error while trying to load the gem 'bullet'. (Bundler::GemRequireError)
Gem Load Error is: uninitialized constant ActiveRecord::VERSION
Backtrace for gem load error is:
/Users/noah/.rvm/gems/ruby-2.3.2@conover-r5/gems/bullet-5.5.1/lib/bullet/dependency.rb:48:in `active_record4?'
/Users/noah/.rvm/gems/ruby-2.3.2@conover-r5/gems/bullet-5.5.1/lib/bullet/dependency.rb:56:in `active_record40?'
/Users/noah/.rvm/gems/ruby-2.3.2@conover-r5/gems/bullet-5.5.1/lib/bullet/dependency.rb:17:in `active_record_version'
/Users/noah/.rvm/gems/ruby-2.3.2@conover-r5/gems/bullet-5.5.1/lib/bullet.rb:12:in `<module:Bullet>'
/Users/noah/.rvm/gems/ruby-2.3.2@conover-r5/gems/bullet-5.5.1/lib/bullet.rb:9:in `<top (required)>'
/Users/noah/.rvm/gems/ruby-2.3.2@conover-r5/gems/bundler-1.14.6/lib/bundler/runtime.rb:91:in `require'
/Users/noah/.rvm/gems/ruby-2.3.2@conover-r5/gems/bundler-1.14.6/lib/bundler/runtime.rb:91:in `block (2 levels) in require'
/Users/noah/.rvm/gems/ruby-2.3.2@conover-r5/gems/bundler-1.14.6/lib/bundler/runtime.rb:86:in `each'
/Users/noah/.rvm/gems/ruby-2.3.2@conover-r5/gems/bundler-1.14.6/lib/bundler/runtime.rb:86:in `block in require'
/Users/noah/.rvm/gems/ruby-2.3.2@conover-r5/gems/bundler-1.14.6/lib/bundler/runtime.rb:75:in `each'
/Users/noah/.rvm/gems/ruby-2.3.2@conover-r5/gems/bundler-1.14.6/lib/bundler/runtime.rb:75:in `require'
/Users/noah/.rvm/gems/ruby-2.3.2@conover-r5/gems/bundler-1.14.6/lib/bundler.rb:107:in `require'
/Users/noah/development/conover/config/application.rb:17:in `<top (required)>'
/Users/noah/.rvm/gems/ruby-2.3.2@conover-r5/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:88:in `require'
/Users/noah/.rvm/gems/ruby-2.3.2@conover-r5/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:88:in `block in server'
/Users/noah/.rvm/gems/ruby-2.3.2@conover-r5/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:85:in `tap'
/Users/noah/.rvm/gems/ruby-2.3.2@conover-r5/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:85:in `server'
/Users/noah/.rvm/gems/ruby-2.3.2@conover-r5/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
/Users/noah/.rvm/gems/ruby-2.3.2@conover-r5/gems/railties-5.0.2/lib/rails/commands.rb:18:in `<top (required)>'
/Users/noah/development/conover/bin/rails:11:in `require'
/Users/noah/development/conover/bin/rails:11:in `<top (required)>'
/Users/noah/.rvm/gems/ruby-2.3.2@conover-r5/gems/spring-2.0.1/lib/spring/client/rails.rb:28:in `load'
/Users/noah/.rvm/gems/ruby-2.3.2@conover-r5/gems/spring-2.0.1/lib/spring/client/rails.rb:28:in `call'
/Users/noah/.rvm/gems/ruby-2.3.2@conover-r5/gems/spring-2.0.1/lib/spring/client/command.rb:7:in `call'
/Users/noah/.rvm/gems/ruby-2.3.2@conover-r5/gems/spring-2.0.1/lib/spring/client.rb:30:in `run'
/Users/noah/.rvm/gems/ruby-2.3.2@conover-r5/gems/spring-2.0.1/bin/spring:49:in `<top (required)>'
/Users/noah/.rvm/gems/ruby-2.3.2@conover-r5/gems/spring-2.0.1/lib/spring/binstub.rb:31:in `load'
/Users/noah/.rvm/gems/ruby-2.3.2@conover-r5/gems/spring-2.0.1/lib/spring/binstub.rb:31:in `<top (required)>'
/Users/noah/development/conover/bin/spring:13:in `require'
/Users/noah/development/conover/bin/spring:13:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
Bundler Error Backtrace:
from /Users/noah/.rvm/gems/ruby-2.3.2@conover-r5/gems/bundler-1.14.6/lib/bundler/runtime.rb:90:in `block (2 levels) in require'
from /Users/noah/.rvm/gems/ruby-2.3.2@conover-r5/gems/bundler-1.14.6/lib/bundler/runtime.rb:86:in `each'
from /Users/noah/.rvm/gems/ruby-2.3.2@conover-r5/gems/bundler-1.14.6/lib/bundler/runtime.rb:86:in `block in require'
from /Users/noah/.rvm/gems/ruby-2.3.2@conover-r5/gems/bundler-1.14.6/lib/bundler/runtime.rb:75:in `each'
from /Users/noah/.rvm/gems/ruby-2.3.2@conover-r5/gems/bundler-1.14.6/lib/bundler/runtime.rb:75:in `require'
from /Users/noah/.rvm/gems/ruby-2.3.2@conover-r5/gems/bundler-1.14.6/lib/bundler.rb:107:in `require'
from /Users/noah/development/conover/config/application.rb:17:in `<top (required)>'
from /Users/noah/.rvm/gems/ruby-2.3.2@conover-r5/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:88:in `require'
from /Users/noah/.rvm/gems/ruby-2.3.2@conover-r5/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:88:in `block in server'
from /Users/noah/.rvm/gems/ruby-2.3.2@conover-r5/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:85:in `tap'
from /Users/noah/.rvm/gems/ruby-2.3.2@conover-r5/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:85:in `server'
from /Users/noah/.rvm/gems/ruby-2.3.2@conover-r5/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
from /Users/noah/.rvm/gems/ruby-2.3.2@conover-r5/gems/railties-5.0.2/lib/rails/commands.rb:18:in `<top (required)>'
from /Users/noah/development/conover/bin/rails:11:in `require'
from /Users/noah/development/conover/bin/rails:11:in `<top (required)>'
from /Users/noah/.rvm/gems/ruby-2.3.2@conover-r5/gems/spring-2.0.1/lib/spring/client/rails.rb:28:in `load'
from /Users/noah/.rvm/gems/ruby-2.3.2@conover-r5/gems/spring-2.0.1/lib/spring/client/rails.rb:28:in `call'
from /Users/noah/.rvm/gems/ruby-2.3.2@conover-r5/gems/spring-2.0.1/lib/spring/client/command.rb:7:in `call'
from /Users/noah/.rvm/gems/ruby-2.3.2@conover-r5/gems/spring-2.0.1/lib/spring/client.rb:30:in `run'
from /Users/noah/.rvm/gems/ruby-2.3.2@conover-r5/gems/spring-2.0.1/bin/spring:49:in `<top (required)>'
from /Users/noah/.rvm/gems/ruby-2.3.2@conover-r5/gems/spring-2.0.1/lib/spring/binstub.rb:31:in `load'
from /Users/noah/.rvm/gems/ruby-2.3.2@conover-r5/gems/spring-2.0.1/lib/spring/binstub.rb:31:in `<top (required)>'
from /Users/noah/development/conover/bin/spring:13:in `require'
from /Users/noah/development/conover/bin/spring:13:in `<top (required)>'
from bin/rails:3:in `load'
from bin/rails:3:in `<main>'
Sorry I meant test new new branch in a regular Rails app as well. I dont expect master to work with your app yet.
I'm following you now, I had assumed you were looking for a comparison of the two branches on my app.
Running a fresh app via rails new on rails@5.1.0
with the new non_active_record
branch doesn't result in any errors during startup and the 'Yay! You're on Rails' message successfully appears on the main page. Did you have any specific tests or checks in mind?
The reason this fix was added was for migrations. I recommend testing this. Thanks for your help by the way.
In the new Rails app, I created a Users
model and generated a few migrations to add/remove fields. Migrations ran successfully and I didn't see any errors in the server logs when starting up. Anything beyond this is probably best tested by another user who is using ActiveRecord in a live app.
Ya sure no worries. This seems good, lets merge this baby and I'll try to get a new version out today.
That will be great, thank you for investigating right away.
Still working on that new version. Can you test the master branch and see if its still working for your non-activerecord use case. If that passes I can release a new version.
It's looking great in my specific use-case. Ship it!
v1.3.0 is now released.
Setup:
rails
5.0.2protected_attributes_continued
1.2.4bullet
,better_errors
, orrack-mini-profiler
rails/all
inconfig/application.rb
, manually loading individual railties and leavingactiverecord
unloadedHello,
In defining a module on
ActiveRecord
in/lib/protected_attributes_continued.rb
, any other gems that check for ActiveRecord seem to falsely assume it has been loaded.I ran into this issue on upgrading a Rails 4 application that makes heavy use of MongoDB via the
mongoid
gem. Sinceprotected_attributes_continued
extends ActiveRecord by default whether it has been included or not, a number of other gems believed that ActiveRecord was in use even though it hadn't been loaded in the Rails startup.I understand this gem is a continuation of the now-unsupported Rails feature and may only be designed to serve the use-case of ActiveRecord models. If that's the case I fully understand, but this was an unexpected consequence of switching from the previous
protected_attributes
gem.