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 trialJames Kirkpatrick
25,001 Pointsbin/rake fails but, I can't find the solution. I've been stuck on this for days. Please help.
rails version = 4.2.0
bin/rake results in: ''' Failures:
1) TodoListsController POST create with invalid params re-renders the 'new' template Failure/Error: response.should render_template("new") expecting <"new"> but rendering with <["todo_lists/edit", "layouts/application"]> # ./spec/controllers/todo_lists_controller_spec.rb:97:in `block (4 levels) in <top (required)>' '''
Links to code:
1 Answer
Brandon Barrette
20,485 PointsSo looking at the error, it tells you where to look:
expecting <"new"> but rendering with <["todo_lists/edit"]>
It is expecting to render with the new (in the create method), but it getting the edit template. So that means there is a typo in your create method. I've pasted it below. Check the else clause. Your test is correct, it should render new and not edit.
# Todo Lists Controller
def create
@todo_list = TodoList.new(todo_list_params)
respond_to do |format|
if @todo_list.save
format.html { redirect_to @todo_list, notice: 'Todo list was successfully created.' }
format.json { render :show, status: :created, location: @todo_list }
else
format.html { render :edit }
format.json { render json: @todo_list.errors, status: :unprocessable_entity }
end
end
end
James Kirkpatrick
25,001 PointsJames Kirkpatrick
25,001 PointsThank you so much for your swift reply. I am currently comparing the two so as to actually fix the typo. I'd rather do it that way than just copy and paste your answer. If I still don't see the difference within a couple of minuets, I may just have to ask you to point it out to me. Again, you have my thanks.
Brandon Barrette
20,485 PointsBrandon Barrette
20,485 PointsNo problem. Good luck and happy coding =)
James Kirkpatrick
25,001 PointsJames Kirkpatrick
25,001 PointsOkay. I've been looking at it. Maybe I'm losing my vision. Or, I've hit my wall (been at this quite a while with very little sleep). Either way, I'm not seeing the typo. Am I missing something here?......yes, I probably am. Can you point it out to me?
James Kirkpatrick
25,001 PointsJames Kirkpatrick
25,001 PointsDuhhh.....Just saw it. was supposed to be "new" not "edit". Silly me. Guess I need some sleep. Thanks so much for your help. Happy coding to you as well.