NameError: uninitialized constant DeviseMultipleTokenAuthDevice - ruby-on-rails

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

Related

How to add iframe to sanitized tags in ruby on rails 4.2.6?

I am trying to add iframe to santized tags by using
config.action_view.sanitized_allowed_tags
I tried to find what tags are already allowed by using the console.
uraai#raiuorial:~/workspace/corse (master) $ heroku run rails c
Running rails c on ⬢ fa4... up, run.9396
Loading production environment (Rails 4.2.6)
irb(main):001:0> puts helper.sanitized_allowed_tags.to_a
NoMethodError: undefined method `sanitized_allowed_tags' for #<ActionView::Base:0x007f18ea91ea60>
from /app/vendor/bundle/ruby/2.3.0/gems/metamagic-3.1.7/lib/metamagic/view_helper.rb:30:in `method_missing'
from (irb):1
from /app/vendor/bundle/ruby/2.3.0/gems/railties-4.2.6/lib/rails/commands/console.rb:110:in `start'
from /app/vendor/bundle/ruby/2.3.0/gems/railties-4.2.6/lib/rails/commands/console.rb:9:in `start'
from /app/vendor/bundle/ruby/2.3.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:68:in `console'
from /app/vendor/bundle/ruby/2.3.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /app/vendor/bundle/ruby/2.3.0/gems/railties-4.2.6/lib/rails/commands.rb:17:in `<top (required)>'
from /app/bin/rails:8:in `require'
from /app/bin/rails:8:in `<main>'
irb(main):002:0>
Any idea how to add it without ignoring the other tags? Thanks
Please have a look on the next example:
module Tapp
class Application < Rails::Application
# In config/application.rb
config.action_view.sanitized_allowed_tags = ['strong', 'em', 'a', 'br', 'iframe']
# ...
end
My app called Tapp, I'm pretty sure you will have another name here ;)
Then in the console:
[retgoat#iMac-Roman ~/workspace/tapp]$ rc
Loading development environment (Rails 4.2.6)
[1] pry(main)> Tapp::Application.config.action_view[:sanitized_allowed_tags]
=> ["strong", "em", "a", "br", "iframe"]

Ruby on Rails error when creating record

I am following the Kevin Skoglund tutorial for Ruby on Rails called Ruby on Rails 4 Essential Training. In the section 'Create Record' I am having the following error after simply trying to create a record:
George$ pwd
/Users/George/Sites/simple_cms
George$ rails console
Loading development environment (Rails 4.2.0)
irb(main):001:0> subject = Subject.new
NameError: uninitialized constant Subject
from (irb):1
from /Users/George/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/railties-4.2.0/lib/rails/commands/console.rb:110:in `start'
from /Users/George/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/railties-4.2.0/lib/rails/commands/console.rb:9:in `start'
from /Users/George/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:68:in `console'
from /Users/George/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /Users/George/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/railties-4.2.0/lib/rails/commands.rb:17:in `<top (required)>'
from /Users/George/Sites/simple_cms/bin/rails:8:in `<top (required)>'
from /Users/George/.rbenv/versions/2.2.0/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/George/.rbenv/versions/2.2.0/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from -e:1:in `<main>'
irb(main):002:0>
As I am still in the early stages of learning I cannot establish what the cause might be although it appears to be gem related based on the errors return.
If anyone has any suggestion and maybe a tip on how I can work out what the error and fix is for myself it would be appreciated as I really want to keep learning.
George$ pwd
/Users/George/Sites/simple_cms
George$ rails console
Loading development environment (Rails 4.2.0)
> rails generate model Subject name:string type:string
> rake db:migrate
> rails console
> sub = Subject.new
Try this.

Rails 4.1 error when use accepts_nested_attributes_for in model

This code for class assignment is ok until rails v4.0.5
but it make an error from rails 4.1.x
there is a api documentation so I guess that it is not deprecated.
I can not know what is the problem of this.
Loading development environment (Rails 4.1.1)
2.1.1 :001 > class Assignment < ActiveRecord::Base
2.1.1 :002?> belongs_to :group
2.1.1 :003?> has_one :event
2.1.1 :004?> accepts_nested_attributes_for :event
2.1.1 :005?> end
NameError: undefined local variable or method `generated_feature_methods' for #<Class:0x0000010a262e28>
from /Users/me/.rvm/gems/ruby-2.1.1#xxx/gems/activerecord-4.1.1/lib/active_record/dynamic_matchers.rb:26:in `method_missing'
from /Users/me/.rvm/gems/ruby-2.1.1#xxx/gems/protected_attributes-1.0.5/lib/active_record/mass_assignment_security/nested_attributes.rb:30:in `block in accepts_nested_attributes_for'
from /Users/me/.rvm/gems/ruby-2.1.1#xxx/gems/protected_attributes-1.0.5/lib/active_record/mass_assignment_security/nested_attributes.rb:16:in `each'
from /Users/me/.rvm/gems/ruby-2.1.1#xxx/gems/protected_attributes-1.0.5/lib/active_record/mass_assignment_security/nested_attributes.rb:16:in `accepts_nested_attributes_for'
from (irb):4:in `<class:Assignment>'
from (irb):1
from /Users/me/.rvm/gems/ruby-2.1.1#xxx/gems/railties-4.1.1/lib/rails/commands/console.rb:90:in `start'
from /Users/me/.rvm/gems/ruby-2.1.1#xxx/gems/railties-4.1.1/lib/rails/commands/console.rb:9:in `start'
from /Users/me/.rvm/gems/ruby-2.1.1#xxx/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:69:in `console'
from /Users/me/.rvm/gems/ruby-2.1.1#xxx/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
from /Users/me/.rvm/gems/ruby-2.1.1#xxx/gems/railties-4.1.1/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
It is ok on Rails 4.0.5
Loading development environment (Rails 4.0.5)
2.1.1 :001 > class Assignment < ActiveRecord::Base
2.1.1 :002?> belongs_to :group
2.1.1 :003?> has_one :event
2.1.1 :004?> accepts_nested_attributes_for :event
2.1.1 :005?> end
=> [:event]
Possible duplicate of Rails 4.1.0.beta1 upgrade gives me undefined local variable or method generated_feature_methods. Like it says there, try updating the protected_attributes gem:
bundle update protected_attributes

Getting a lot of extra error information ".../commands/console.rb:..."

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?

Access first record of table in Rails Console Results in NoMethodError

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.

Resources