User.pins is giving me error in Rails Console - ruby-on-rails

I am running into an error on Rails Console. When I type user.pins, I receive an error. Below is the text in the console that I get. Any help is appreciated, thanks!
2.1.2 :008 > user.pins
NoMethodError: undefined method pins' for #<User:0x007fa029493808>
from /Users/jovanhernandez/.rvm/gems/ruby-2.1.2/gems/activemodel-4.1.6/lib/active_model/attribute_methods.rb:435:inmethod_missing'
from /Users/jovanhernandez/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/attribute_methods.rb:211:in method_missing'
from (irb):8
from /Users/jovanhernandez/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/commands/console.rb:90:instart'
from /Users/jovanhernandez/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/commands/console.rb:9:in start'
from /Users/jovanhernandez/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/commands/commands_tasks.rb:69:inconsole'
from /Users/jovanhernandez/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/commands/commands_tasks.rb:40:in run_command!'
from /Users/jovanhernandez/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/commands.rb:17:in'
from bin/rails:8:in require'
from bin/rails:8:in'

Related

Receiving Error - NoMethodError: undefined method `collection' for nil:NilClass for any query I run in rails console. Connected database is mongo db

I have a project where docker is being used with which i have setup the project and now i am running docker-compose run app rails c to seed data in the database. Database which is being used is Mongo DB.
But somehow for every query like User.all or User.create, everything has an error as follows:
NoMethodError: undefined method collection' for nil:NilClass from /usr/local/bundle/gems/mongo_mapper-0.13.1/lib/mongo_mapper/plugins/persistence.rb:58:in collection'
from /usr/local/bundle/gems/mongo_mapper-0.13.1/lib/mongo_mapper/plugins/querying.rb:51:in query' from /usr/local/bundle/gems/mongo_mapper-0.13.1/lib/mongo_mapper/plugins/sci.rb:70:in query'
from /usr/local/bundle/gems/mongo_mapper-0.13.1/lib/mongo_mapper/plugins/identity_map.rb:61:in query' from (irb):1 from /usr/local/bundle/gems/railties-5.0.0.1/lib/rails/commands/console.rb:65:in start'
from /usr/local/bundle/gems/railties-5.0.0.1/lib/rails/commands/console_helper.rb:9:in start' from /usr/local/bundle/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:78:in console'
from /usr/local/bundle/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:49:in run_command!' from /usr/local/bundle/gems/railties-5.0.0.1/lib/rails/commands.rb:18:in <top (required)>'
from bin/rails:4:in require' from bin/rails:4:in '
I have tried to find solution but not getting appropriate answer

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?

Getters/settings not working when using the rails-setting gem - method missing error

I'm using the rails-settings gem: https://github.com/huacnlee/rails-settings-cached
The getter/setter method are not working.
I've added the following line to my user model as directed:
include RailsSettings::Extend
I've also tried adding it to role.rb (as I am using rolify gem)
However is am still getting the following error message:
NoMethodError: undefined method `settings' for #<User:0x007f8dd017a560>
from /Users/jamieturner/.rvm/gems/ruby-2.0.0-p353#accufly/gems/activemodel-3.2.13/lib/active_model/attribute_methods.rb:407:in `method_missing'
from /Users/jamieturner/.rvm/gems/ruby-2.0.0-p353#accufly/gems/activerecord-3.2.13/lib/active_record/attribute_methods.rb:149:in `method_missing'
from /Users/jamieturner/.rvm/gems/ruby-2.0.0-p353#accufly/gems/rolify-3.2.0/lib/rolify/role.rb:73:in `method_missing'
from (irb):24
from /Users/jamieturner/.rvm/gems/ruby-2.0.0-p353#accufly/gems/railties-3.2.13/lib/rails/commands/console.rb:47:in `start'
from /Users/jamieturner/.rvm/gems/ruby-2.0.0-p353#accufly/gems/railties-3.2.13/lib/rails/commands/console.rb:8:in `start'
from /Users/jamieturner/.rvm/gems/ruby-2.0.0-p353#accufly/gems/railties-3.2.13/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
When I run:
user = User.find(2)
user.settings.color = :red
Can anyone see what the issue is?
Ok, I've solved the issue.
I had not restarted the console session.....restarting it got it working!

Error instantiating mechanize object

I have no idea what the problem is on this. I'm trying this in the rails console:
>> agent = Mechanize.new
NoMethodError: undefined method `user' for nil:NilClass
I added gem 'mechanize' and did a bundle install. I did require 'mechanize'. I also tried require 'nokogiri' below that, and every time I get the same error. I've tried 4 or 5 different ways to instantiate a new mechanize object and haven't been able to find one.
I searched my entire rails app for the string '.user' and couldn't find any. Not sure what the deal is here. Any ideas?
Thanks
EDIT
Full Stack trace
NoMethodError: undefined method `user' for nil:NilClass
from /home/me/.rvm/gems/ruby-1.9.3-p448#my_app/gems/net-http-persistent-2.9.2/lib/net/http/persistent.rb:866:in `proxy='
from /home/me/.rvm/gems/ruby-1.9.3-p448#my_app/gems/mechanize-2.7.2/lib/mechanize/http/agent.rb:1189:in `set_proxy'
from /home/me/.rvm/gems/ruby-1.9.3-p448#my_app/gems/mechanize-2.7.2/lib/mechanize.rb:204:in `initialize'
from (irb):5:in `new'
from (irb):5
from /home/me/.rvm/gems/ruby-1.9.3-p448#global/gems/railties-3.2.15/lib/rails/commands/console.rb:47:in `start'
from /home/me/.rvm/gems/ruby-1.9.3-p448#global/gems/railties-3.2.15/lib/rails/commands/console.rb:8:in `start'
from /home/me/.rvm/gems/ruby-1.9.3-p448#global/gems/railties-3.2.15/lib/rails/commands.rb:41:in `<top (required)>'
from /home/me/Dropbox/Work/RubymineProjects/apps/my_app/script/rails:6:in `require'
from /home/me/Dropbox/Work/RubymineProjects/apps/my_app/script/rails:6:in `<top (required)>'
from -e:1:in `load'
from -e:1:in `<main>'
You're not doing anything wrong: the version of mechanize that came out a few days ago is buggy. I solved that error just updating the gem (i.e., with bundle update mechanize).

Class method returning NoMethodError: undefined method Rails

I am writing a class method to find certain data in my database however I am getting a NoMethodError: undefined method error. I am using Datamapper instead of ActiveRecord. Here is my error output:
NoMethodError: undefined method `get_courses_starting_in' for Course:Class
from /Users/hugo/.rvm/gems/ruby-1.9.2-p318/gems/dm-ar-finders-1.2.0/lib/dm-ar-finders.rb:155:in `method_missing_with_find_by'
from /Users/hugo/Web Development/Rails/connectedtrips/lib/ct_gems/dm-core-1.2.0/lib/dm-core/model/relationship.rb:372:in `method_missing'
from /Users/hugo/Web Development/Rails/connectedtrips/lib/ct_gems/dm-core-1.2.0/lib/dm-core/model/property.rb:249:in `method_missing'
from (irb):24
from /Users/hugo/.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/commands/console.rb:47:in `start'
from /Users/hugo/.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/commands/console.rb:8:in `start'
from /Users/hugo/.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
And here is my class method:
def self.get_courses_starting_in
courses = []
Course.all.each{ |course| courses << course if course.days_till_course_starts == 7}
return courses
end
I hope someone can help. Thanks.
Have you write the code after starting the console? Restart console and check again.

Resources