I'm in the Rails Tutorial working on the exercises at the end of Chapter 2 and I'm stumped. www.railstutorial.org/book/toy_app#sec-toy_app_exercises
Assignment 2 says, "Update Listing 2.19 by replacing FILL_IN with the appropriate code to validate the presence of name and email attributes in the User model (Figure 2.20). "
And it's pretty straight forward Listing 2.19:
Adding presence validations to the User model. app/models/user.rb
class User < ActiveRecord::Base
has_many :microposts
validates FILL_IN, presence: true
validates FILL_IN, presence: true
end
First thing I did was the typical noob mistake and just copied in the code straight out of the listing. System came back and asked me what this variable "FILL_IN" was.
Next thing i did, was to try putting in the field names in my user.rb file
class User < ActiveRecord::Base
has_many :microposts
validates name, presence: true
validates email, presence: true
end
Running this, gets me a the following error "NameError in UsersController#create" "undefined local variable or method `email' for #"
Rails is acting like it doesn't recognize the email, or name fields from my model.
I have tried capitalizing Name and Email, I have tried making them plurals, I have tried going to "rails console" to validate that I created the fields "name" and "email" correctly (I did).
I have tried looking for an answer to this, the closet I came was someone just pasting in the FILL_IN lines and getting harpooned for it.
I'm hoping that I haven't missed something just as obvious, but I'm prepared for it if I did.
@Octopus-Paul Awesome, the colon(:) before the variable names is exactly what I needed.
class User < ActiveRecord::Base
has_many :microposts
validates :name, presence: true
validates :email, presence: true
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With