I am facing a problem with JWT gem file after I upgrade my rails version from 4.2 to 5.0.
Can anybody please help me.
I am using Rails - 5.0.7.2
Ruby - 2.5.3
JwT - 2.2.1
require 'jwt'
payload = { data: 'test' }
token = JWT.encode payload, nil, 'none'
Traceback (most recent call last):
8: from bin/rails:11:in <main>' 7: from bin/rails:11:in require'
6: from /home/sahu/.rvm/gems/ruby-2.5.3/gems/railties-5.0.7.2/lib/rails/commands.rb:18:in <top (required)>' 5: from /home/sahu/.rvm/gems/ruby-2.5.3/gems/railties-5.0.7.2/lib/rails/commands/commands_tasks.rb:49:in run_command!'
4: from /home/sahu/.rvm/gems/ruby-2.5.3/gems/railties-5.0.7.2/lib/rails/commands/commands_tasks.rb:78:in console' 3: from /home/sahu/.rvm/gems/ruby-2.5.3/gems/railties-5.0.7.2/lib/rails/commands/console_helper.rb:9:in start'
2: from /home/sahu/.rvm/gems/ruby-2.5.3/gems/railties-5.0.7.2/lib/rails/commands/console.rb:65:in start' 1: from (irb):3 NoMethodError (undefined method encode' for JsonWebToken:Module)
I tried by downgrade the Jwt gem version but still facing same issue.
and also getting warnings like below -
/home/sahu/.rvm/gems/ruby-2.5.3/gems/json_web_token-0.3.5/lib/json_web_token.rb:36: warning: already initialized constant JWT
/home/sahu/.rvm/gems/ruby-2.5.3/gems/jwt-2.2.1/lib/jwt/base64.rb:5: warning: previous definition of JWT was here
Finally, I found the problem.
Before upgrading my rails version I have JWT Gem and After I Upgrade my rails version. I added a new gem intuit-oauth. This gem has a dependency on json_web_token gem. So after I installed intuit-oauth gem, It automatically installed json_web_token gem. Due to this gem, the JWT object was changed. like when I click on access JWT in the console. It returns as JsonWebToken object. Maybe this gem overrides JWT gem. So for a temporary solution, I removed intuit-oauth gem. and it works fine. Thank you.
Related
So it's been a while since I fired up the old Rails server. It took a lot of tricks to even get the bundle to install... but eventually I upgraded from Rails 4.2.6 to 4.2.9. The bundle installs just fine. I'm on Ruby 2.3.0. But now the problem is... whenever I try to run:
rails s
I get the following error:
rails-html-sanitizer.rb:2:in `require': cannot load such file -- loofah (LoadError)
from /home/rainless/.rvm/gems/ruby-2.3.0#rails3.2.16/gems/rails-html-sanitizer-1.0.3/lib/rails-html-sanitizer.rb:2:in `<top (required)>'
from /home/rainless/.rvm/gems/ruby-2.3.0#global/gems/bundler-1.7.9/lib/bundler/runtime.rb:76:in `require'
from /home/rainless/.rvm/gems/ruby-2.3.0#global/gems/bundler-1.7.9/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
from /home/rainless/.rvm/gems/ruby-2.3.0#global/gems/bundler-1.7.9/lib/bundler/runtime.rb:72:in `each'
Or some variation of that.
At first I was getting around this by uninstalling whatever the Gem that was said to be unable to load (in this case "loofah" but I've done it with many more), and then adding it to the Gemfile and installing it using Bundler. I now realize that the list is never-ending:
gem 'rails-html-sanitizer'
gem 'chronic'
gem 'multipart-post'
gem 'oauth-active-resource'
gem 'rack-test'
gem 'multi_json'
gem 'addressable'
gem 'orm_adapter'
All the above couldn't load. I ran Rails for years before this... and I know this isn't the way it's supposed to work. Any help/advice on what could be going wrong?
If you see carefully in the error message, it says ruby-2.3.0#rails3.2.16 but you mentioned "upgraded from Rails 4.2.6 to 4.2.9." . For some reason, it's still referring to rails3.2.16. Therefore it could be you need to install the rails-html-sanitizer globally. By the way, Loofah is only needed if you wanted to use it in a non-rails app. Refer to the docs here.
Rails Html Sanitizer is only intended to be used with Rails
applications. If you need similar functionality in non Rails apps
consider using Loofah directly (that's what handles sanitization under
the hood).
from /home/rainless/.rvm/gems/ruby-2.3.0#rails3.2.16/gems/rails-html-sanitizer-1.0.3/lib/rails-html-sanitizer.rb:2:in `<top (required)>'
After finding this stackoverflow q/a about how to click on an element based on its coordinates, I'm trying to do so to click on a button I've discussed in this question. Currently having to use the cliclick shell command for mac osx which is clunky. Anyway, here is the section of my Gemfile showing the watir related gems in order -- perhaps I've required more gems than is necessary?
gem 'selenium-webdriver'#, '2.45.0'
gem 'selenium'#, '0.2.11'
gem 'watir', '5.0.0'
Here's the full command I've run to get the error:
b = Watir::Browser.new #defaults to firefox
#...
element = b.span(:text => "Confirm Selection")
b.driver.action.move_to(element, 15, 15).click.perform
#=>
TypeError: expected Selenium::WebDriver::Element, got #<Watir::Button:0x39fe077c86d90f06 located=false selector={:id=>"id_280", :tag_name=>"button"}>:Watir::Button
from /Users/davo/.rvm/gems/ruby-2.2.1/gems/selenium-webdriver-2.53.0/lib/selenium/webdriver/common/mouse.rb:86:in `assert_element'
from /Users/davo/.rvm/gems/ruby-2.2.1/gems/selenium-webdriver-2.53.0/lib/selenium/webdriver/common/mouse.rb:69:in `move_to'
from (irb):79
from /Users/davo/.rvm/gems/ruby-2.2.1/gems/railties-4.0.0/lib/rails/commands/console.rb:90:in `start'
from /Users/davo/.rvm/gems/ruby-2.2.1/gems/railties-4.0.0/lib/rails/commands/console.rb:9:in `start'
from /Users/davo/.rvm/gems/ruby-2.2.1/gems/railties-4.0.0/lib/rails/commands.rb:64:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Let me know if any more details would help.
System details:
rails 4.0.0
mac osx el capitan 10.11.1
firefox 46.0.1
selenium gem 0.2.11
selenium-webdriver gem 2.53.0
watir gem 5.0.0
watir-webdriver gem 0.9.1
The problem is that a Watir::Element is being passed to Selenium's action builder. The action builder only knows about Selenium::WebDriver::Element.
To convert a Watir::Element to a Selenium::WebDriver::Element, use the wd method:
element.wd
The move_to call should be:
b.driver.action.move_to(element.wd, 15, 15).click.perform
I'm very new to Rails, and I'm trying to build a user authentication system with 'devise', but I am failing. I'm following Rails Girls Guides's tutorial on adding authentication using the gem 'devise'. Once I got to step 5, which is to set up the User model, I received this error after running rake db:migrate
rake aborted!
NoMethodError: undefined method `merge!' for #<ActionDispatch::Routing::Mapper::Scope:0x007fd3397a7448>
/Users/.rvm/gems/ruby-2.1.2/gems/devise-3.0.4/lib/devise/rails/routes.rb:420:in `ensure in with_devise_exclusive_scope'
/Users/.rvm/gems/ruby-2.1.2/gems/devise-3.0.4/lib/devise/rails/routes.rb:420:in `with_devise_exclusive_scope'
/Users/.rvm/gems/ruby-2.1.2/gems/devise-3.0.4/lib/devise/rails/routes.rb:233:in `block (2 levels) in devise_for'
/Users/.rvm/gems/ruby-2.1.2/gems/devise-3.0.4/lib/devise/rails/routes.rb:336:in `block in devise_scope'
Has anyone solved this error? I've looked at all solutions such as not generating user model before installing devise, running bundle install, running rails g devise:install, and more. Nothing has worked so far when I'm trying to use devise for Rails 4.0.
Also, does anyone have recommendations on what tutorials I can follow to build an authentication system? I've tried a lot so far, and none has worked.
This looks to be a know bug with prior 3.4.0 devise.
Upgrading it should make this error go away.
To do that edit your Gemfile where you have gem "devise" <might have some other stuff in front> and change it to gem "devise", '~> 3.4.1'
then run bundle update devise and you are done.
Trying to run the following using Rails 3.2.2, switched to 3.2.1 and tried another machine to see if it was more core / OS related.
I try:
rails g bootstrap:themed events
I get:
.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.1/lib/active_support/inflector/methods.rb:229:in `const_defined?': wrong constant name event (NameError)
from /Users/charleyhine/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.1/lib/active_support/inflector/methods.rb:229:in `block in constantize'
from /Users/charleyhine/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.1/lib/active_support/inflector/methods.rb:228:in `each'
from /Users/charleyhine/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.1/lib/active_support/inflector/methods.rb:228:in `constantize'
from /Users/charleyhine/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.1/lib/active_support/core_ext/string/inflections.rb:54:in `constantize'
from /Users/charleyhine/.rvm/gems/ruby-1.9.3-p0/gems/twitter-bootstrap-rails-2.0.4/lib/generators/bootstrap/themed/themed_generator.rb:58:in `columns'
from (erb):6:in `template'
No need to downgrade the gem version. Instead, just change:
rails g bootstrap:themed events
to:
rails g bootstrap:themed Events
You need to capitalize and pluralize the model name, which is dumb, but it works
I was getting the same error. After searching for similar errors - I figured it must be a problem with the latest version of bootstrap, as I was not getting this error earlier.
I got the error with the version 2.0.4. The following line in the Gemfile followed by "bundle install" solved it for me.
gem 'twitter-bootstrap-rails', '2.0.2'
I just changed my Rails 2.3.8 project to load gems using Bundler, rather than the default Rails 2.3 loading mechanism. I followed the official instructions and the site runs fine in development. I use RVM for gem management, and have a specific gemset loaded for the application.
My RSpec test suite is unable to run, however. I have tried running both the entire suite and single tests using a variety of commands:
autospec # My usual way of running tests
rake spec
spec .
spec spec/models/comment_spec.rb # Trying a single spec file in isolation
ruby spec/models/comment_spec.rb
I have also tried running them all prefixed with bundle exec. Everything returns the same error:
/Users/casper/.rvm/gems/ruby-1.8.7-p248#darebusters/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:440:in `load_missing_constant': uninitialized constant InheritedResources::Base (NameError)
from /Users/casper/.rvm/gems/ruby-1.8.7-p248#darebusters/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:80:in `const_missing_not_from_s3_library'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248#darebusters/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb:206:in `const_missing'
from /Users/casper/Projects/cf/darebusters/app/controllers/admin/base_controller.rb:1
from /Users/casper/.rvm/gems/ruby-1.8.7-p248#darebusters/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:158:in `require'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248#darebusters/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:158:in `require'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248#darebusters/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:265:in `require_or_load'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248#darebusters/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:224:in `depend_on'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248#darebusters/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:136:in `require_dependency'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248#darebusters/gems/rails-2.3.8/lib/initializer.rb:414:in `load_application_classes'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248#darebusters/gems/rails-2.3.8/lib/initializer.rb:413:in `each'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248#darebusters/gems/rails-2.3.8/lib/initializer.rb:413:in `load_application_classes'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248#darebusters/gems/rails-2.3.8/lib/initializer.rb:411:in `each'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248#darebusters/gems/rails-2.3.8/lib/initializer.rb:411:in `load_application_classes'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248#darebusters/gems/rails-2.3.8/lib/initializer.rb:197:in `process'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248#darebusters/gems/rails-2.3.8/lib/initializer.rb:113:in `send'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248#darebusters/gems/rails-2.3.8/lib/initializer.rb:113:in `run'
from /Users/casper/Projects/cf/darebusters/config/environment.rb:9
from /Users/casper/Projects/cf/darebusters/spec/spec_helper.rb:5:in `require'
from /Users/casper/Projects/cf/darebusters/spec/spec_helper.rb:5
from spec/models/comment_spec.rb:1:in `require'
from spec/models/comment_spec.rb:1
I'm pretty sure the problem is not related to the Inherited Resources gem - I think gems are not loaded at all at this point, and Inherited Resources just happens to be the first one needed.
The thing that's baffling me is that /activesupport-2.3.8/lib/active_support/dependencies.rb:158 requires /app/controllers/admin/base_controller during the initialization phase. It shouldn't do that, and it certaintly doesn't do it in development mode. I can comment out gem 'inherited_resources' in my Gemfile, and site still runs. It's not until I hit an action that loads a controller that use Inherited Resources I get the "uninitialized constant" error.
For clarity, here's my Gemfile and spec_helper.rb.
Even older question, but I had the same issue with Bundler 1.0.3, Rspec-Rails 1.3.3 & Rails 2.3.8 and was able to boil it down to remarkable_rails. Remarkable-Rails seems to load rspec/rails before the initializers are run by the environment.
After adding :require => nil to it in the Gemfile and requiring it by hand in spec_helper AFTER requiring the rails-environment the issue disappeared.
I realize this is an old question, but I just came across the same problem.
I had the 1.3.0 version of rspec and rspec-rails required by my application. Looking at the rspec-rails changelog, I noticed there were a few bug fixes after 1.3.0. Upgrading rspec-rails to 1.3.2 fixed everything for me.
To fix this problem I changed by Gemfile from:
gem 'rspec-rails', '~> 1.3.2', :require => 'spec/rails'
to
gem 'rspec-rails', '~> 1.3.2'
and added the following to my spec helper
require 'spec/rails'