I'm getting an error message when I try to go inside the admin dashboard by the rails_admin gem.
Error
undefined method `new' for nil:NilClass
This is the whole code
klass.setup if klass.respond_to? :setup
#authorize = proc do
#authorization_adapter = klass.new(*([self] + args).compact)
end
elsif block
#authorize = block
It is pointing to this spot
#authorization_adapter = klass.new(*([self] + args).compact)
I don't know why this happening because I did not touch anything from the rails admin
To anyone who is scratching their head over this issue and stumbled upon this thread, on /config/initializers/rails_admin.rb try replacing
config.authorize_with :cancan
with
config.authorize_with :cancancan
Related
Rails 6.1.3.1
Rspec
basic behavior spec code:
describe "index" do
it "should show me the list" do
visit dashboard_targets_path
end
end
the routes file
namespace :dashboard do
resources :targets
end
error shows me the exception, but strangely it appears as if it isn't calling through to the app, just fails right in my test code:
1) interaction for Dashboard::TargetsController index should show me the list
Failure/Error: visit dashboard_targets_path
NoMethodError:
undefined method `empty?' for nil:NilClass
# ./spec/system/dashboard/targets_behavior_spec.rb:16:in `block (3 levels) in <top (required)>'
# /Users/jason/.rvm/gems/ruby-2.6.6/gems/webmock-3.12.2/lib/webmock/rspec.rb:37:in `block (2 levels) in <main>'
# /Users/jason/.rvm/gems/ruby-2.6.6/gems/rspec-wait-0.0.9/lib/rspec/wait.rb:46:in `block (2 levels) in <main>'
it seems to be failing inside the test code, if I drop into the debugger there and run dashboard_targets_path directly I also get the same exception, so the problem is just using the helper within the TEST ENVIRONMENT
within the dev environment, this function works
the problem here was the the config/environments/test.rb file does have default_url_options.
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
when you hit errors that disappear into the Rails gems, a good way to debug them is like so:
begin
// your failing code here
rescue StandardError => e
puts e.backtrace
byebug
puts e.inspect
raise (e)
end
WARNING: do not leave this code in your app or check it in unless you explicitly want to use exception handling for flow control (not recommended!). This is recommended ONLY for debugging purposes.
here you will see the full backtrace to the line number in the Gem where it is failing. when debugging Gems be careful— remember to un-do any changes you make and know that your monkey-patching inside of the Gem code doesn't affect your production code.
I have defined actions and rules to reward users thanks to merit gem.
However, It does not work. After having execute the rewarded actions , the user does not take any points.
Here is my code:
first , here is my view:
<div class="col-md-3 text-center">
<p class="dark-blue"><%= #user.points %></p>
<p class="grey-light">Points</p>
</div>
Secondly, here is the point_rules model:
#Model/merit/point_rules.rb
module Merit
class PointRules include Merit::PointRulesMethods
def initialize
score 15, on: 'pages#create', to: [:user]
end
end
end
Thirdly, the method create in the pages Controller:
def create
#comment = Comment.new
#comment.title = params[:title]
#comment.content = params[:content]
#comment.created_at = params[:created_at]
#comment.score = 0
#comment.author = User.find(session[:user_id]).user_name
#comment.user = User.find(session[:user_id])
#comment.save
redirect_to "/feed"
end
Finally,the merit.rb:
#config/initializers/merit.rb
Merit.setup do |config|
# Check rules on each request or in background
config.checks_on_each_request = true
# Define ORM. Could be :active_record (default) and :mongoid
config.orm = :active_record
# Add application observers to get notifications when reputation changes.
# config.add_observer 'MyObserverClassName'
# Define :user_model_name. This model will be used to grand badge if no
# `:to` option is given. Default is 'User'.
config.user_model_name = 'User'
# Define :current_user_method. Similar to previous option. It will be used
# to retrieve :user_model_name object if no `:to` option is given. Default
# is "current_#{user_model_name.downcase}".
config.current_user_method = 'current_user'
# Add application observers to get notifications when reputation changes.
# config.add_observer 'MyObserverClassName'
end
Furthermore, Forest tells my in the CLI that "The association "sash" does not seem to exist for model "Merit::ActivityLog".
How to solve that?
thanks you in advance.
EDIT :
here are the stack traces of the possible error[merit] no target found: uninitialized constant Page.
/Users/charbe/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/merit-3.0.1/lib/merit/base_target_finder.rb:13:in `find'
[merit] no target found: uninitialized constant Page. /Users/charbe/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/merit-3.0.1/lib/merit/base_target_finder.rb:13:in `find'
[merit] no target found: uninitialized constant Page. /Users/charbe/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/merit-3.0.1/lib/merit/base_target_finder.rb:13:in `find'
[merit] no target found: uninitialized constant Page. /Users/charbe/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/merit-3.0.1/lib/merit/base_target_finder.rb:13:in `find'
[merit] no target found: uninitialized constant Page. /Users/charbe/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/merit-3.0.1/lib/merit/base_target_finder.rb:13:in `find'
[merit] no target found: uninitialized constant Page. /Users/charbe/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/merit-3.0.1/lib/merit/base_target_finder.rb:13:in `find'
[merit] NoMethodError on `TrueClass#user` (called from Merit::TargetFinder#other_target)
[merit] NoMethodError on `TrueClass#user` (called from Merit::TargetFinder#other_target)
Merit doesn't work with Rails 4.2.
https://github.com/merit-gem/merit/issues/301
You have to use
gem 'merit', '~>2.4'
Also the error NoMethodError on 'TrueClass#user' means that something is returning true when it is expecting an object that responds to #user.
Where does the call to the isolation_level come from?
My module fails at a.save!
module AppsHelpers
def self.create_app!
a = App.new
a.save!
a
end
end
The specific NoMethodError:
Failure/Error: #app = AppsHelpers::create_app!
NoMethodError:
undefined method `isolation_level' for ActiveRecord::Base:Class
What could possibly cause this failure?
System:
ruby 1.9.3p448
Rails 3.2.8
This was simple. I was calling a method defined in the Transactional Isolation gem: The stacktrace was not helpful because I was calling it from an installed gem and this was a missing dependency.
I started my rails app and suddenly got the following error
/.rvm/gems/ruby-1.9.3-p194/gems/devise-2.1.2/lib/devise.rb:406:in `configure_warden!': undefined method `failure_app=' for nil:NilClass (NoMethodError)
devise.rb line 406 has:
warden_config.failure_app = Devise::Delegator.new
I cannot figure out the problem, how do i go about this?
I know this has to be something stupid, but I keep getting the following error in one of my examples:
undefined method `new' for #<Class:0x211d274>
I have created a simple example to show the error:
describe LateCharge do
before :each do
#membership = Membership.new
#location = mock_model(Location, :late_payment_rate => 10)
end
it "should initialize" do
LateCharge.respond_to?('new').should == true
#charge = LateCharge.new(#membership, #location)
end
end
The strange part is, when I run the example by itself, it passes. When I run it with all my examples, it fails with the following error:
NoMethodError in 'LateCharge should initialize'
undefined method `new' for #<Class:0x211d274>
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:1964:in `method_missing_without_paginate'
/Users/l33/.gem/ruby/1.8/gems/mislav-will_paginate-2.3.11/lib/will_paginate/finder.rb:170:in `method_missing'
./spec/models/late_charge_spec.rb:15:
It is failing on the line: #charge = LateCharge.new(#membership, #location)
I do not have any problems instantiating the LateCharge object at run time or from the console.
Anyone have any ideas?
Seems to me the following information is key to your issue:
will_paginate/finder.rb:170:in `method_missing'
Hey Lee - not sure if you're still having this problem, but I had the exact same thing and it's because another spec I had was unstubbing the function.