I'm using watir in my Rails application.
I did simple commands and got a error:
2.3.0 :001 > require 'watir-webdriver'
/home/user/.rvm/gems/ruby-2.3.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require': `require "watir-webdriver"` is deprecated. Please, use `require "watir"`.
=> true
2.3.0 :002 > browser = Watir::Browser.new
NoMethodError: undefined method `[]' for nil:NilClass
from (irb):2:in `new'
from (irb):2
I need any help or suggestions on this point, thanks.
By default Watir is using chromedriver
Related
Hello Programmers & Developers!!!, I'm facing a problem in rails console when I tried to access DeviseMultipleTokenAuthDevice then I'm getting the following error :
Loading development environment (Rails 4.2.0)
2.2.4 :001 > DeviseMultipleTokenAuthDevice
NameError: uninitialized constant DeviseMultipleTokenAuthDevice
from (irb):1
from /Users/vishal/.rvm/gems/ruby-2.2.4#devise_demo/gems/railties-4.2.0/lib/rails/commands/console.rb:110:in `start'
from /Users/vishal/.rvm/gems/ruby-2.2.4#devise_demo/gems/railties-4.2.0/lib/rails/commands/console.rb:9:in `start'
from /Users/vishal/.rvm/gems/ruby-2.2.4#devise_demo/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:68:in `console'
from /Users/vishal/.rvm/gems/ruby-2.2.4#devise_demo/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /Users/vishal/.rvm/gems/ruby-2.2.4#devise_demo/gems/railties-4.2.0/lib/rails/commands.rb:17:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
2.2.4 :002 >
Following gems I'm using in my project for user authentication
gem 'devise'
gem 'devise_multiple_token_auth'
Following are the tables in my record :
2.2.4 :002 > p ActiveRecord::Base.connection.tables
["schema_migrations", "users", "devise_multiple_token_auth_devices"]
=> ["schema_migrations", "users", "devise_multiple_token_auth_devices"]
2.2.4 :003 >
For more info you can follow these links :
Source from where I followed the instruction
My Github repo link for project source
Other required information
Ruby Version 2.2.4
Rails Version 4.2.0
Database PSQL
The solution for the same is, we've to create a file called devise_multiple_token_auth_device.rb in app/models/
here is the code for devise_multiple_token_auth_device.rb file
class DeviseMultipleTokenAuthDevice < ActiveRecord::Base
belongs_to :user
end
I'm using find_all_by to get the returned array from active record, and this feature works well for Rails(4.0.0)
Loading production environment (Rails 4.0.0)
2.0.0-p353 :001 > Subscription.find_all_by_id 123
=> []
But when I changed it to Rails(4.1.5), find_all_by doesn't work, and throw undefined method error
Loading production environment (Rails 4.1.5)
2.0.0-p481 :001 > Subscription.find_all_by_id 123
NoMethodError: undefined method `find_all_by_id' for #<Class:0x00000004d71b68>
from /usr/local/rvm/gems/ruby-2.0.0-p481/gems/activerecord-4.1.5/lib/active_record/dynamic_matchers.rb:26:in `method_missing'
from (irb):1
from /usr/local/rvm/gems/ruby-2.0.0-p481/gems/railties-4.1.5/lib/rails/commands/console.rb:90:in `start'
from /usr/local/rvm/gems/ruby-2.0.0-p481/gems/railties-4.1.5/lib/rails/commands/console.rb:9:in `start'
from /usr/local/rvm/gems/ruby-2.0.0-p481/gems/railties-4.1.5/lib/rails/commands/commands_tasks.rb:69:in `console'
from /usr/local/rvm/gems/ruby-2.0.0-p481/gems/railties-4.1.5/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
from /usr/local/rvm/gems/ruby-2.0.0-p481/gems/railties-4.1.5/lib/rails/commands.rb:17:in `<top (required)>'
Any ideas to fix it or work around it?
How about this?
Subscription.where(id: "123").to_a
For anyone else who has been trying to get find_all_by to work and have had no success, find_all_by has been deprecated and removed from rails.
Source: https://github.com/rails/rails/issues/17357
I am half way through building a Q&A app and I have successfully seeded my database and can see that objects have been created both in my browser and in the server logs and previously in irb. Now when I went to try to inspect an object in irb, for every object I give it, irb returns "NameError: uninitialized constant". For example:
2.0.0-p481 :001 > user = User.find(1)
NameError: uninitialized constant User
from (irb):1
from /home/vagrant/.rvm/rubies/ruby-2.0.0-p481/bin/irb:12:in `<main>'
2.0.0-p481 :002 > question = Question.find(1)
NameError: uninitialized constant Question
from (irb):2
from /home/vagrant/.rvm/rubies/ruby-2.0.0-p481/bin/irb:12:in `<main>'
2.0.0-p481 :003 > user = User.find
NameError: uninitialized constant User
from (irb):3
from /home/vagrant/.rvm/rubies/ruby-2.0.0-p481/bin/irb:12:in `<main>'
2.0.0-p481 :004 > user = User.new
NameError: uninitialized constant User
from (irb):4
from /home/vagrant/.rvm/rubies/ruby-2.0.0-p481/bin/irb:12:in `<main>'
I'm new to programming, so if anyone could explain why this might be happening it would be much appreciated!
It looks like you're running irb when you want rails console (or rails c for short).
Because you need to use rails console, not irb.
rails console
(I assume you are building a Rails application)
I'm working on a ruby on rails tutorial and using the rails console
When an error occurs I'm seeing a lot more error information than the tutorial shows (could be that they ommited it for brevity)
For example:
2.1.1 :001 > asdf
NameError: undefined local variable or method `asdf' for main:Object
from (irb):1
from /Users/me/.rvm/gems/ruby-2.1.1#global/gems/railties-4.0.4/lib/rails/commands/console.rb:90:in `start'
from /Users/me/.rvm/gems/ruby-2.1.1#global/gems/railties-4.0.4/lib/rails/commands/console.rb:9:in `start'
from /Users/me/.rvm/gems/ruby-2.1.1#global/gems/railties-4.0.4/lib/rails/commands.rb:62:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
2.1.1 :002 >
Whereas the tutorial would only show:
2.1.1 :001 > asdf
NameError: undefined local variable or method `asdf' for main:Object
Is that other information useful? Is there a way to suppress it?
I'm using Rails 3.2.12 and Roby 2.0.0-p0 in RVM etc. In rails console I get the following error after doing u = Users.first:
u = Users.first
Loading production environment (Rails 3.2.12)
2.0.0p0 :001 > u = Users.first
NoMethodError: undefined method `first' for Users:Module
from (irb):1
from /usr/local/rvm/gems/ruby-2.0.0-p0#discourse/gems/railties-3.2.12/lib/rails/commands/console.rb:47:in `start'
from /usr/local/rvm/gems/ruby-2.0.0-p0#discourse/gems/railties-3.2.12/lib/rails/commands/console.rb:8:in `start'
from /usr/local/rvm/gems/ruby-2.0.0-p0#discourse/gems/railties-3.2.12/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
I was able to access the database and view the record via the psql console using the user rails would be using.
If you already have a User model defined, try User.first instead of Users.first.