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
Michele Guido
6,671 PointsNoMethodError in StatusesController#create
I don't know what happened, but I screwed some stuff up along the way. I've been trying to debug so I can move on to making the profile pages but I am stuck. I think maybe I screwed something up because I tried erasing my database because I thought that was the problem. Anyway, here is the error message I get when I try to post a new status:
NoMethodError in StatusesController#create undefined method `content' for #<Status:0x00000102ed1b08>
app/controllers/statuses_controller.rb:47:in `block in create'
app/controllers/statuses_controller.rb:46:in `create'
Request
Parameters:
{"utf8"=>"?",
"authenticity_token"=>"v3ZC7xMy8tn7GqF/NekIyP+fq5WTPrj2vYyfmHXVXGE=",
"status"=>{"user_id"=>"",
"context"=>"this is a test"},
"commit"=>"Create Status"}
Response
Headers:
None
here are lines 46 and 47 from statuses_controller.rb
respond_to do |format|
if @status.save
Help! Please! :)
2 Answers
Twiz T
12,588 PointsCan You post your entire statuses controller and status model?
Luqman Shah
188 PointsAre you still able to open a rails server? If yes then just start over from where you messed up (not saying restart the whole project)
Michele Guido
6,671 PointsI haven't been saving as I go, I don't know where I messed it up. Lesson learned :(
Michele Guido
6,671 PointsMichele Guido
6,671 Pointsstatuses_controller.rb
status.rb
Twiz T
12,588 PointsTwiz T
12,588 PointsLook like you might have the attribute defined as 'context' instead of 'content' look at the file in db/schema.rb and look under the status table to see if you originally defined it as 'content' or 'context'. The status can't be created because rails is getting "confused" about this. Or just look at how it is defined in your forms.
My guess is if you switch
validates :contentto
validates :context
rails would allow the status to be created. Just as along as you have consistent naming (whatever it may be) you should be alright :) Let me know if that doesn't work by posting your db/schema/rb file or if you have any other questions.
-twiz
Michele Guido
6,671 PointsMichele Guido
6,671 Pointswoohoo! thank you! I remember there was some confusion when I was writing that part, something didn't work for me and I saw here on the forum someone fixed it by writing context instead of content or the other way around and I must have forgotten the next time that came up. All good now!