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 Build a Simple Ruby on Rails Application Customizing Forms Creating Relationships

Bennett Collen
Bennett Collen
6,270 Points

Adding :user_id input yields NoMethodError

First step of this video is to add <%= f.input :user_id %> to line 14 in _form.html.erb

My lines 14-18 look like this (identical to the video unless I'm missing something:

 <%= f.input :user_id %>
  <%= f.input :content %>
   <div class="form-actions"> 
    <%= f.button :submit %>
  </div>

When I do this I get the following error in my browser: NoMethodError in Statuses#new

Showing /Users/cogna/Projects/treebook/app/views/statuses/_form.html.erb where line #14 raised:

undefined method `user_id' for #<Status:0x007f82f396eec0> Extracted source (around line #14):

11:     </div>
12:   <% end %>
13: 
14:   <%= f.input :user_id %>
15:   <%= f.input :content %>
16:    <div class="form-actions"> 
17:     <%= f.button :submit %>

I tried some of the fixes suggested elsewhere in this forum but nothing has worked so far. Any suggestions?

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

This looks more complex. Can you put your whole project on Github and link it here?

I'm with Maciej Czuchnowski, your markup looks fine (like you said, exactly like the video). It's looking like maybe you don't have the association between Status and User setup possibly.

Bennett Collen
Bennett Collen
6,270 Points

Hi guys thanks for the quick response. Here is the link to the project on Github https://github.com/COGNAME/treebook

5 Answers

Daniel Belvin was correct in stating that they have changed Rails with the new release. In Rails 4.2.0 they now use "Strong Parameters". Here is a link to StackOverflow workaround: http://stackoverflow.com/questions/17371334/how-is-attr-accessible-used-in-rails-4

Also the link to the Ruby Docs regarding "Strong Parameters": http://edgeapi.rubyonrails.org/classes/ActionController/StrongParameters.html

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

Your first problem is the duplication of one of the migrations. If you run rake db:migrate now, you will get an error. I managed to migrate the database properly only when I removed the file 20130405220917_add_devise_to_users.rb from db/migrate folder and did rake db:reset in the console. The error I'm getting from your code is undefined method `name' for #<Status:0x00000003442ae8> and it's caused by putting attributes in the status form that do not exist in the status model. You must have mixed some things up when following the videos.

Bennett Collen
Bennett Collen
6,270 Points

I was unable to replicate your results. I removed the file and ran rake db:reset in the console, but that too returned an error. Any suggestions?

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

Aside from starting the project from scratch, I have no suggestions. I don't know where to start with the current state.

Daniel Belvin
Daniel Belvin
163 Points

I'm getting the same error. Though, at this point, it's probably due to the video being out of date with the latest version of Rails I'm using :/

Bennett Collen
Bennett Collen
6,270 Points

Yes, very frustrating, I wasn't able to work through this and never had the time to start the project from scratch

Sorin Pantis
Sorin Pantis
6,769 Points

I was able to solve this problem by following Maciej Czuchnowski 's article from here https://teamtreehouse.com/community/not-storing-firstname-lastname-profilename, then stop the rails server, run rake db:reset, start the server again and re-create an account.