I'm getting a strange error message, not much information is given and i'm quite confused.
undefined method ` ' for #<User::PhoneNumbersController:0x007ff2259fa320>
router.rb
namespace :user do
resources :phone_numbers, only: [:new, :create]
end
controllers/user/phone_numbers_controller.rb
class User::PhoneNumbersController < User::UserController
def new
@phonenumber = PhoneNumber.new
end
end
models/phone_number.rb
class PhoneNumber < ActiveRecord::Base
belongs_to :user
end
It's failing at this line: @phonenumber = PhoneNumber.new
Is my design pattern wrong? the stack trace doesn't say much...
Thanks to Max's answer
I indeed have "fallen victim to to the evil non-breaking space character" or NBSP. I had one on the left of the instance variable @phonenumber
.
You have fallen victim to to the evil non-breaking space character or one of its cousins such as the hair space.
While visibly identical the Ruby parser does not treat the non-breaking space character U+00A0
the same as the normal U+0020
character. Ruby instead treats it as an identifier. Which is why you get undefined method ` '
.
Turn on the hidden characters in your editor and go hunting for those pesky NBSP's.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.