Questions tagged [nomethoderror]

A Ruby exception that is raised when a method is called on an object which doesn't respond to that method.

A NoMethodError exception is raised in Ruby when a method is called on an object that doesn't respond to that method and that doesn't have a method_missing hook to respond to it.

529 questions
44
votes
4 answers

What is the difference between `try` and `&.` (safe navigation operator) in Ruby

Here is my code: class Order < Grape::Entity expose :id { |order, options| order.id.obfuscate } expose :time_left_to_review do |order, options| byebug order&.time_left_to_review # ERROR end expose :created_at { |order, options|…
Adrien
  • 1,838
  • 1
  • 15
  • 34
30
votes
4 answers

Ruby - Module :: NoMethodError

I have a module like this: module Prober def probe_invoke(type, data = {}) p = Probe.new({:probe_type => type.to_s, :data => data.to_json, :probe_status => 0, :retries => 0}) p.save end end And I am trying to access this from my…
Sayuj
  • 6,836
  • 11
  • 54
  • 73
24
votes
3 answers

rails < 4.0 "try" method throwing NoMethodError?

Why is try throwing an error? Doesnt that defeat the whole purpose? Maybe its just in the console? ruby-1.9.2-p180 :101 > User.first.try(:something) NoMethodError: undefined method `something' for # from…
hb922
  • 909
  • 1
  • 10
  • 22
22
votes
4 answers

Rails 3.2 undefined method `key?' for nil:NilClass

For some reason I started to get this error after switching to Rails 3.2. I guess it has something to do with acl9 plugin, which I tried reinstalling, but nothing changed. I moved the plugins to lib/plugins and added initializer to…
Stpn
  • 5,346
  • 7
  • 43
  • 86
15
votes
1 answer

spring/application.rb:161 undefined method `reject!' for nil:NilClass (NoMethodError)

I am using ruby 2.5 and rails 5.0.1 for my application. when i try to run console or generate controller or migration it gives me this error: Running via Spring preloader in process 6473 Loading development environment (Rails 5.0.1) Traceback (most…
Abdul Wahed
  • 327
  • 3
  • 12
13
votes
2 answers

NoMethodError (undefined method `permit' for #

I am getting this error and using Rails 5. NoMethodError (undefined method permit' for # app/controllers/traumas_controller.rb:99:intrauma_params' app/controllers/traumas_controller.rb:25:in…
Kiran Patil
  • 361
  • 4
  • 15
12
votes
2 answers

Rails 4: undefined method `relation_delegate_class' for Model:Class

I am trying to follow this coderwall tutorial about Creating a Scoped Invitation System for Rails. In my Rails 4 app, I have the following models: class User < ActiveRecord::Base has_many :administrations has_many :calendars, through:…
12
votes
2 answers

Ruby protected visibility calling from superclass

I have this little code that seems to contradict in some way Ruby's documentation: The second visibility is protected. When calling a protected method the sender must be a subclass of the receiver or the receiver must be a subclass of the sender.…
Rodrigo
  • 2,332
  • 1
  • 11
  • 32
9
votes
2 answers

Undefined method `<' error when attempting to install homebrew

So I'm trying to install homebrew on my Macbook Pro in order to be able to run NINJA-IDE, and every time I execute the code that is given on the site I get this: Joshs-MacBook-Pro:~ joshua$ ruby -e "$(curl -fsSL…
Josh Spern
  • 93
  • 4
9
votes
2 answers

NoMethodError - undefined method 'find_by' for []:ActiveRecord::Relation

I've been following Michael Heartl tutorial to create a follow system but I have a strange error: "undefined method `find_by' for []:ActiveRecord::Relation". I'm using devise for authentication. My view /users/show.html.erb looks like that: . . . <%…
titibouboul
  • 1,238
  • 2
  • 14
  • 25
8
votes
4 answers

Undefined method password_changed? Error

I'm trying to set my program so that the password only is validated if it is changed (so a user can edit other information without having to put in their password). I am currently getting an error that says NoMethodError in…
8
votes
1 answer

NoMethodError: undefined method `match?' for "Ruby":String

I'm trying to check whether input from user matches RegEx [a-zA-z] so I've checked the docs for proper method. I found match? in Ruby-doc.org and copied the example shown in docs to irb, but instead of true I'm getting this: 2.3.3 :001 >…
ToTenMilan
  • 510
  • 1
  • 6
  • 15
8
votes
4 answers

Ruby: NoMethodError, but why?

I was working on a simple Pi Generator while learning Ruby, but I kept getting NoMethodError on RubyMine 6.3.3, so I decided to make a new project and new class with as simple as possible, and I STILL get NoMethodError. Any reason? class Methods …
Annie the Eagle
  • 135
  • 1
  • 1
  • 8
7
votes
1 answer

Backbone - Object render has no method 'apply'

I am getting the error: object render has no method apply for the below code. What can be the reason ? The html page doesnt contain any code except the link for the javascript. what should I do to remove the error ? (function($) { window.Book…
user1305989
  • 2,663
  • 2
  • 21
  • 33
7
votes
6 answers

Rails + CarrierWave: NoMethodError: undefined method `name' for nil:NilClass

I am using CarrierWave with Rails 3.1. I am getting the following error message when I submit the form (trying to upload an image): Error Message: ActiveRecord::StatementInvalid in Admin::PostsController#create NoMethodError: undefined method…
Robert Audi
  • 7,199
  • 8
  • 41
  • 65
1
2 3
35 36