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

Problem with Devise in Simple Ruby on Rails App

So I have been doing the simple app for Ruby on Rails but I run into a problem. For those that have seen it, when the teacher goes to change it to display the actual username after making the relationship, I just get errors that the methods are undefined for showing the full_name or anything related to that.

So I went into my ruby console and pulled up the User.all. There is one user registered but the :first_name, :last_name, and :profile_name are all set to nil. So I delete that record and go to re-register. Those fields are on my register page but again I check the User.all and the user is again created but with those 3 fields are nil.

So using the console I do user = User.find(#) and then user.update_column :first_name, "Aaron" and so forth for the three fields, I run User.all and this time the three fields are set. So I go to set my statuses and I get an error that theres an undefined method. So I delete all of my post via the console and the index page loads.

I try and make a status but I get an error that says "NoMethodError in Statues#show. "undefined method "full_name" for nil:NilClass. So I tried switching it to @status.user.first_name and still the same error. I view the Status.all in the console and it has the :user_id set to nil. What am I doing wrong. If I update that to the proper user id via the console it works. Where am I messing up in the process? Any ideas or suggestions?

Are you using the correct Ruby version 1.9.3 and the correct Rails version 3.2?

3 Answers

Thanks for the help! I found a fix. If I run into problems though I will remember what you said about switching the ruby and rails versions.

What I did (in case anyone else sees this and is having this problem) was I created this folder and file app/controllers/users/registrations_controller.rb

I then wrote this inside of it

class Users::RegistrationsController < Devise::RegistrationsController

  def sign_up_params
     params.require(:user).permit(:first_name, :last_name, :profile_name, :email, :password, :password_confirmation)
  end

end

Then I went into my routes file and changed the devise line to this

devise_for :users, :controllers => {:registrations => "users/registrations"}

Looks like we're all set to go for now. Found this answer here: https://teamtreehouse.com/forum/strongparameters-and-treebook

This is what I get when I run this in terminal

Rails --version Rails 4.0.2

ruby -v ruby 2.0.0p352

Does that mean I am using the wrong version? I am still pretty new to all of this

Update: Ok I got the status part to work. What I did was go to the app folder/controllers/statuses_controller.rb

At the very end of the file theres this: def status_params params.require(:status).permit(:name, :content) end

So I changed that to permit the :user_id too

def status_params params.require(:status).permit(:name, :content, :user_id) end

Now I can post comments and manually set the user_id in the form as they are doing (which is the step I left off at). I still can't get a user to register where the firstname, lastname and profile name are all stored.I tried to register another user but it still leaves those three fields as nil. Since I am on the newer rails I couldn't do attr_accessible so I skipped that step so maybe that has something to do with it

Yes you are using the wrong version of rails you will need to use rvm(ruby version manager) to install 1.9.3 then rails 3.2 and start it again.

Im not great on rails but had the same nightmare at the start as it will cause problems later on if your using the wrong direction. A few Google searches will guide you to ensure you install the correct versions

Hope this helps

Dave Faliskie
Dave Faliskie
17,793 Points

Aaron, I'm having some of the same problems. I am also using an updated version of ruby and rails, did you switch versions or were you able to finish the project with 4.0.2 and 2.0? I noticed this is from 6 months ago so any input on this project and versions would be awesome.