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 trialDaan Oosting
2,203 PointsBy adding if banana.safe head 200 end the previous step throws an error saying i need to declare create.
Been scratching my head on this one for a while, but i can't seem to figure it out.
class Api::BananasController < ApplicationController
def create
banana = Banana.new(banana_params)
if banana.safe
head 200
end
end
private
def banana_params
params.require("banana").permit("name")
end
end
3 Answers
William Li
Courses Plus Student 26,868 Pointstry
def create
@banana = Banana.new(banana_params)
if @banana.save
head 200
end
end
I forgot to mention earlier that banana is supposed be an instance variable.
Daan Oosting
2,203 PointsHi William, that's correct, but in the next step they ask you to add this to the code. And all new code is added to previous steps. So i get an error in a step i have already completed.
William Li
Courses Plus Student 26,868 Pointssorry, about that, I was thinking that you're only referring to part 1, let me check for you.
Daan Oosting
2,203 PointsYes! That did it! It's weird that they do not cover it like that in the videos. Thanks William, enjoy your Sunday.
William Li
Courses Plus Student 26,868 Pointsno problem, Daan. And I'm sure once you passed part 2, part 3 should be a piece of cake, right? Enjoy your weekend too
Daan Oosting
2,203 PointsAbsolutely! :)