Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Liju George
Liju George
5,433 Points

Creating Relationship Error for nil values [solved]

for the errors that happen during creating relationship tutorial please read the steps below...i knw the text is a bit non readable..its bcause of the strange markup of the comments..there is a scrollbar at the bottom for those who didnt see it..better still..copy the whole stuff into a text editor and read through :)

3 Answers

Liju George
Liju George
5,433 Points
Here is how i got the issue resolved..please note.. I don't knw what all errors are there in the future tutorials as I haven't reached them yet. I set off to fix this one first.  
Also pls note that indentation,new lines,spaces  etc are very imp while writing the codes. Also case sensitivity:
Lets us start step by step:

Step -1: 
a. Add this line to the Gemfile    gem 'protected_attributes'
b. type  bundle install
c. This will install the gem..u can read the specification on their github page if u wish

Step 0: Delete all the statuses and users:
a. Goto rails console by typing: rails console
b. type Status.delete_all
c. u can see all the statuses deleted
d.type User.delete_all
e. u can see all the users deleted as well

Step 1: How your  treebook>app>models>status.rb file should look:

class Status < ActiveRecord::Base
    attr_accessible :content, :user_id

Step 2: How your treebook>app>models>user.rb file should look:

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable
  attr_accessible :first_name, :last_name, :profile_name, :email, :password, :password_confirmation

Step 3: How your treebook>app>controllers>application_controller.rb file should look:

class ApplicationController < ActionController::Base 

before_filter :configure_permitted_parameters, if: :devise_controller?

def configure_permitted_parameters 

devise_parameter_sanitizer.for(:sign_up) << :first_name 
devise_parameter_sanitizer.for(:sign_up) << :last_name 
devise_parameter_sanitizer.for(:sign_up) << :profile_name
devise_parameter_sanitizer.for(:sign_up) << :email
devise_parameter_sanitizer.for(:sign_up) << :password
devise_parameter_sanitizer.for(:sign_up) << :password_confirmation
protect_from_forgery with: :exception

Step 4: Save all the files
Step 5: Start rails server by typing: rails s
Step 6: Go to the web app and register a new user at localhost:3000/user/sign_up
Step 7: Add a new status
Step 8: Stop the server: Ctrl+C
Step 9: Goto rails console: rails console
Step 10: Type user = User.first
Step 11: You can see the new user has been created with all the data filled.
Step 12: Continue with the tutorial Creating relationships and forward.

After this i dont knw wats gonna happen..if other errors come up in later stages..need to research and fix them then!!
the show must go on!! :)
Brandon Barrette
Brandon Barrette
20,485 Points

You are getting those errors because rails 4 doesn't use protected attributes. The reason it was eliminated is because it's not so secure. If using rails 4, I recommend researching what was changed and how you can use the appropriate rails 4 methods.

Then, to learn rails, just install version 3.2 to learn with the videos. Then you won't spend countless hours trying to fix something that is not as secure.

Liju George
Liju George
5,433 Points

Very true Brandon..this was just a fix which i found to be working for the current scenario and I was able to move forward with the next set of vids.That is why i posted it. I too recommend shifting to 3.2 for these tutorials and am going to do exactly that.