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
Mike Carlucci
1,982 PointsCreating Relationships error
I'm getting a NoMethodError in Statuses#index for line #9 raised undefined method '+' for nil:NilClass
6.
- <% @statuses.each do |status| %>
- <div class="status">
- <strong><%= status.user.full_name %></strong>
- <p><%= status.content %></p>
- <div class="meta">
- <%= link_to time_ago_in_words(status.created_at) + " ago", status %>
11 Answers
Robert Cekay
12,460 Pointsyou guys need to update this video series, all I know how to do is what you tell me and google is useless
Jason Seifer
Treehouse Guest TeacherBased on this error, it looks like one of your statuses is missing the created_at attribute. Try launching the console and deleting all of the statuses like Jim does in this video: http://teamtreehouse.com/library/programming-2/build-a-simple-version-of-facebook/customizing-forms/getting-the-latest-changes. Then, create a few more and that should fix it.
Mike Carlucci
1,982 PointsExcellent. Thanks, that did the trick.
Mike Carlucci
1,982 PointsOk. That only fixed the problem until a new status is added.
I reverted back to the start of the Changing Relationships lesson.
I can create a status fine until adding <%= status.user.first_name %> to my index.html.erb file, in between the <strong> tags..
After adding that I get NoMethodError in Status#index line #5 for show.html.erb with line 5 being <%= @status.user.first_name %>
Mike Carlucci
1,982 PointsCouldn't get it to work no matter what. Redid the project from the start, works perfectly. Must have made a small error somewhere the first time that I just couldn't see, but I'm back on the rails now!
Jon Thomas
8,916 PointsYep, that worked for me too. Thanks guys!
Simon Pacheco
1,995 PointsI am getting an error as well when trying to click create new status. This is the error that I get:
NoMethodError in Statuses#new
Showing /Users/si/treebook/app/views/statuses/_form.html.erb where line #16 raised:
undefined method `name' for #<Status:0x007f8fd58ba800> Extracted source (around line #16):
13: 14: <div class="field"> 15: <%= f.label :name %><br /> 16: <%= f.text_field :name %> 17: </div> 18: <div class="field"> 19: <%= f.label :content %><br />
Jason Seifer
Treehouse Guest TeacherHey Simon, try following along with Jim in that video I linked above and let us know if you still have trouble.
Thibaud CLEMENT
96 PointsJason,
I am encountering a problem with the same video, but the situation is quite different:
- I am able to choose the user_id when I go to http://localhost:3000/statuses/5/edit
- If I save the edit, go to the show view, and come back, the user_id has actually been saved.
- When I add <%= @status.user.first_name %> to show.html.erb, save the file and refresh the status page, nothing changes: the page is working (there is no ErrorMethod messages like my fellow students) but the user's name (first name in this case) does not appear.
I tryed to build Treebook once and stumbled upon the very same problem. So, I restarted from the very first video to make sure I had not made any mistake. But I ended up with the exact same problem and feel stuck right now.
Notice: I am using Ruby 2.0 and Rails 4.0 (and therefore had to deal with the fact that attr_accessible was replaced by strong parameters).
Any idea on how I can fix the app to be able to keep on learning?
Jason Seifer
Treehouse Guest TeacherThibaud CLEMENT Jesse Neal Are you both using Rails 4? You may need to add the user_id to the list of permitted attributes in the statuses_controller.
Thibaud CLEMENT
96 PointsHi Jason Seifer,
Thanks for your reply.
Yes, I am using Rails 4.
I had read about the change in Rails 4 about attr_accessible and therefore I had placed the following into my statuses_controller:
''' def status_params params.require(:status).permit( :content, :user_id) end '''
However, this led to the problem described above.
I just saved all my work and pushed it to GitHub if you want to check it: https://github.com/thibaudclement/treebook/commit/5d0ba5cc48bda86afd77cb1e51e0222f83e5c041
What do you think?
Jason Seifer
Treehouse Guest TeacherThibaud CLEMENT you'll need to add a devise controller and update the permitted parameters there. It's not allowing the first name, last name, and profile name when you sign up. Here's an example gist that highlights what you'll have to do.
Thibaud CLEMENT
96 PointsJason Seifer thank you very much for your help.
Not sure I understood what you meant.
But here is what I have done (which is not working): I created a registrations_controller.rb file with the following code inside:
‘‘‘ class Users::RegistrationsController < Devise::RegistrationsController
before_filter :configure_permitted_parameters
protected
# my custom fields are :first_name, :last_name, :profile_name def configure_permitted_parameters devise_parameter_sanitizer.for(:status) do |u| u.permit(:first_name, :last_name, :profile_name) end end
end ‘‘‘
Does that make sense?
What am I missing?
Thank you.
nofx1717
5,096 PointsJason,
I am having this same issue. Everything works fine, I followed the Jim video several times and deleted all the statuses. I can add a new one, but once I add <%= @status.user.full_name %> in index.html, and show.html I get the no method.
What is weird is that the code on github that Jim pushed up has this in show.html.erb:
<p> <b>Name:</b> <%= @status.user.full_name %> </p>
and in index.html.erb it has this:
<strong><%= status.user.full_name %></strong>
I have also tried deleting all statusus, rolling back my db and refreshing that. Still no dice.
As soon as I remove <%= status.user.full_name %>, I can create all the status updates that I want. Any idea how to fix this?