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

undefined method `user_id' for #<SimpleForm::FormBuilder

HI all,

I'm at the "customizing forms" section and having an issue- I get "no method error" on a show page at:

<%= @status.user.first_name %>

and "undefined method `user_id' for"

#<SimpleForm::FormBuilder

Im using Rails 4, Devise bootstrap gem has been bundled and generated, and my status model belongs_to :user - I'm at a loss. I feel there is something going on with Devise.

Please advise.

What does your controller look like for the show method??

Darn, its blank. Perhaps I missed something? What do you have there?

4 Answers

Well I'd have to go back and look but if this is the statuses controller then this may work

@statuses = Status.all

or if you want want to sort them

@statuses = Status.order("created_at desc").all

Which controller is this??

Right now when you create a new status, there is not user_id getting associated to it.

if you create a status, then go into the rails console and find that status

Status.find(1) 

or

Status.first

if its the first status and you will see nil as the value for user_id

Okay here is what your statuses controller should be

def new
  @user = current_user
  @status = @user.statuses.new
end

def create
  @user = current_user
  @status = @user.statuses.new(status_params)

  respond to...........
end

make sure you go to your console and reset your database though or else it will find previous statuses you created that have no user associated to them

Just to clarify the respond to part can stay the same (i just did the ....... to save time)

if you need to know how to reset your database, just go to the rails console by typing

rails c

then type

rake db:reset

then type

rake db:migrate

then you'll just have to go in there and create another user and you should be good to go!

Ill try tha one more timeYesterday . I explored the db with a sqlite db explorer for osx and set them to my user number- user_id is not being saved/associated upon creation.

I didn't quite understand that but I downloaded your files and got it to work with those changes to the statuses controller and resetting the db.

Awesome. Ill give it a shot. Thanks so much!!