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

Ruby

Stuck at creating relationship lesson

I am following this rails application.

http://teamtreehouse.com/library/build-a-simple-ruby-on-rails-application/customizing-forms/creating-relationships

When I look at the status table the user_id is not getting updated. I am following all the steps in the tutorial.

I have committed my code to github.

https://github.com/jontychatla/treebook

6 Answers

I see that you have a status belongs_to :user, but you do not have the reciprocal. A user has_many :statuses also. This creates the relationship link between the two fully.

I have fixed the mapping of the relationships. Please check my git commit. I am getting following error when I am trying to access first_name. Also through rails console I checked that the first_name, last_name and profile_name are not getting updated.

undefined method `first_name' for nil:NilClass

Extracted source (around line #5

<p> <strong>Name:</strong> <%= @status.user.first_name%> </p> <p>

Have you completed this lesson?

You are missing many core concepts that are created/explained in the lesson.

I have followed the lesson. I am at 5:52 on the video. When I check the tables first_name, last_name and profile_name is not set.

Changing the application_controller.rb with following code allowed the application to save the first_name, last_name and profile_name. Rails 4 and Devise are not compatible (For custom fields the code needs to be modified.)

<code> class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception before_filter :configure_permitted_parameters, if: :devise_controller?

protected def configure_permitted_parameters devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:email, :password, :password_confirmation, :first_name, :last_name, :profile_name) } end

end </code>

Yes, because of strong_parameters you must tell the devise controller which fields will be used (instead of the default fields email, password, password_conformation). Happy you got it working!