Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Ruby

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
end

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
end

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?

protected 
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
end
protect_from_forgery with: :exception
end

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.