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 trialSean Perryman
13,810 PointsError message shown in video using newest Rails instead of video version
I am using the most current version of Ruby/Rails (as of May 12, 2014), and I didn't get that same error message as what was shown in the video. Consequently, I do not see the section he is talking about in the user.rb file. Does the newer version of Devise not need those same configuration attributes any longer? The way that Jason talks about it, it would seem fairly important.
20 Answers
Naomi Freeman
Treehouse Guest TeacherYes, it is important. You have to set it up in your application controller instead:
Naomi Freeman
Treehouse Guest Teacherk I sent you a pull request.
It doesn't do the thing you want it to yet. But it does show user_id.
The videos are a bit mucky in the next few sections, but you'll come out the other end with current_user stuff and full_name stuff. So for now, coast on the user_id thing.
I added some devise parameters to your application_controller.rb This is instead of the old attr_accessible stuff.
I added :first_name :last_name in the .permit at the bottom of your statuses controller. Every single time you add a new database column, you must add it to be permitted in the appropriate controllers.
the meat of the problem was this: You needed a matching migration for your statuses. Your statuses were aware of users but your users weren't aware of statuses (I believe that's the right way around).
I ran rails generate migration AddStatusesToUsers status:references to generate this migration (see it in migrate, the most recent string of numbers):
class AddStatusesToUsers < ActiveRecord::Migration
def change
add_reference :users, :status, index: true
end
end
Then run rake db:migrate
These relationships then need defined in the models. So you had status belongs_to :user but not the matching user has_many :statuses (which I've added).
Then, in every view you want to call the name, you have to change it. So in statuses > index.html.erb and in statuses > show.html.erb
I've left it at user_id for a particular reason right now lol Just roll with it. Promise it gets easier after this weird stuff. They're about to make you undo a bunch of work you're doing, so don't get too stressed.
Good luck!
P.S. to merge the pull request, it should be easy. On your github, there's a big green button. There shouldn't be any conflicts unless you were still editing while I was editing. It should just pull them together.
Remember to run
git pull
then
rake db:migrate
once you have merged the changes on github.
Sean Perryman
13,810 PointsThat does seem to be a pretty big change; I tried implementing it the way that Jim says in the videos and it flat out breaks the app. I will look at what you are suggesting above; it would seem that if I am going to do this for real I am going to have to find my way around sometimes. Thanks for the reply!
Sean Perryman
13,810 PointsThe link provided above seemed to have done the trick. Browse to your app/controllers/statuses_controller.rb. Near the bottom, you will find the comment that begins: '# Never trust parameters from the scary internet'. In the params.require statement, you will see :name. I replaced this with :user_id, and the application started working as expected.
Naomi Freeman
Treehouse Guest TeacherAwesome :) Glad it worked out.
Sean Perryman
13,810 Pointssummerspirit, he has us enter the 'belongs_to :user' in the status model, but it doesn't seem to work for me. I get an error when I try to use "@status.user.first_name". It is trying to call the first_name method instead of pulling a field.
On a side note, I when I am creating new users it doesn't write the first name/last name/profile name fields to the database. Those three positions are left at nil; so I am assuming I missed a step somewhere.
Naomi Freeman
Treehouse Guest TeacherMmmm is it up on github? Can you link me?
Sean Perryman
13,810 PointsSure! http://github.com/sean-perryman/treebook
I just pushed up the current code I am working on, thanks for looking at it!
Sean Perryman
13,810 PointsI think I got it down, but it isn't migrating for some reason. I see the .db you added, but when i run rake db:migrate it just ends without performing the migration.
I did what github told me to and merged your changes. I also made sure to re-checkout the master branch before trying to migrate.
I took this course when it was still very young, only had a could of videos, but it is seeming fairly confusing to me. Definitely glad I have, though, as I was considering one of the online training camps for Ruby on Rails and might not have done well enough to make it worth it. I do plan on sticking it out, as this is very interesting, I think that the whole rails version issue is just kicking my butt.
Sean Perryman
13,810 PointsSo it looks like the changes you made are not all on my local repo. Working through that at the moment (not very saavy with git)
Naomi Freeman
Treehouse Guest TeacherDid you do it in this order?
merge on github
git pull in your terminal
rake db:migrate in your terminal?
Naomi Freeman
Treehouse Guest TeacherChecked your github. Looks like it hasn't been merged yet.
Naomi Freeman
Treehouse Guest TeacherJust see "Merging a pull request on Github"
https://help.github.com/articles/merging-a-pull-request
Ignore the local stuff for now.
Naomi Freeman
Treehouse Guest Teacherk it let me know that you merged :)
So now in your terminal, do git pull. That will bring the internet changes to you locally.
Sean Perryman
13,810 PointsI think that I got it, just had to re-read over the github instructions again. It seems when I tried to pull (I think) it was having issues, so the first time I fixed the issues but didn't re-pull. Migrate went through this time, I really appreciate all the help!
Naomi Freeman
Treehouse Guest TeacherNo problem :) Leaving work soon so there might be some delays in my response. But I'll try and keep an eye if you need help.
Sean Perryman
13,810 PointsSo the problem I am currently having is with not having a first_name or last_name in the database for the users I add. I even went so far as to modify the devise/registrations/edit.html.erb to include the first_name and last_name fields (thinking I could edit my user and add those it), but upon saving they are still not being inserted to the DB. Any thoughts?
Naomi Freeman
Treehouse Guest TeacherApologies I didn't get back to you last night. Ended up out. Any progress?
My immediate thought is that your status isn't set up right yet to put through first_name last_name. Right now, it's accepting user_id, as a random value you type in.
As you move through the next set of videos, it will link up all the pieces so you're using full_name or first_name or current_user.
It'll move you to a dropdown and then to something else and much later will come to individual profiles so that a user can't pick another user's name.
Just leave first_name for now, use the id, accept the videos are wonky and know that it'll come out the other side much cleaner :)
I'd walk you through it, but they do a few changes and pretty much redo the whole thing you just set up. The videos will be more helpful than me over the next bit. Stick with user_id for now.
Sean Perryman
13,810 PointsNo apologies necessary, you've been quite helpful! I plan on finishing this track out, and possibly re-running it with rails 3.26. I do feel like I am getting a lot out of it, but it would have been super helpful if Jim Hoskins could put in a quick video at the start of this series just saying to download Rails 3 for this tutorial. As it stands, there is an intro rails tutorial set that has you install it through 'rbenv', and then on this track I am on they tell you to install it another way.
Over all I am happy with the progress I made, it is just a bit frustrating when you know about a concept but not what to search to figure it out.
Naomi Freeman
Treehouse Guest TeacherYeah no problem. This challenge you're currently having is not a Rails 3/4 issue. It's just them doing the videos funny and jumping in weird places.
The Rails 4 issues are related to attr_accessible/strong params, Devise's implementation and, much later, Paperclip, nesting and update attributes.
Good luck!
Naomi Freeman
Treehouse Guest TeacherNaomi Freeman
Treehouse Guest TeacherAnd disregard everyone in the forum saying to not use Rails 4. You have to irl anyways lol