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 trialBarry Timilow
31 PointsStrange error
I am receiving an error and I am not sure what the problem is. I have uploaded my work to github here https://github.com/hondoh/ODOT
Adding todo items
is successful with valid content (FAILED - 1)
Failures:
1) Adding todo items is successful with valid content
Failure/Error: click_button "Save"
ActiveModel::ForbiddenAttributesError:
ActiveModel::ForbiddenAttributesError
# ./app/controllers/todo_items_controller.rb:13:in `create'
# ./spec/features/todo_items/create_spec.rb:17:in `block (2 levels) in <top (required)>'
Finished in 0.4593 seconds
1 example, 1 failure
Failed examples:
rspec ./spec/features/todo_items/create_spec.rb:13 # Adding todo items is successful with valid content
Randomized with seed 63928
1 Answer
Maciej Czuchnowski
36,441 PointsTry changing your todo items controller (lines 13 and 25):
class TodoItemsController < ApplicationController
def index
@todo_list = TodoList.find(params[:todo_list_id])
end
def new
@todo_list = TodoList.find(params[:todo_list_id])
@todo_item = @todo_list.todo_items.new
end
def create
@todo_list = TodoList.find(params[:todo_list_id])
@todo_item = @todo_list.todo_items.new(todo_item_params)
if @todo_item.save
flash[:success] = "Added todo list item."
redirect_to todo_list_todo_items_path
else
flash[:error] = "There was a problem adding that todo list item."
render action: :new
end
end
private
def todo_item_params
params.require(:todo_item).permit(:content)
end
end
Barry Timilow
31 PointsBarry Timilow
31 PointsIt worked thanks! Can you tell me why this fixes the problem and is not the method that Jason uses in the video?
Maciej Czuchnowski
36,441 PointsMaciej Czuchnowski
36,441 PointsThe thing I did in line 13 is the same thing that was in the code that I downloaded under the video. It creates a new item and assigns parameters received from the form and filtered through the private method in line 25. Line 25 can stay the way it was before, but I prefer it this way. You should do some research on Strong Parameters: http://www.lynda.com/Ruby-Rails-tutorials/Mass-assignment-strong-parameters/139989/159116-4.html