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 Build a Todo List Application with Rails 4 Build a Todo List Application with Rails 4 Marking Todo Items Complete

Ki Bum Kim
Ki Bum Kim
1,520 Points

Mark Complete's Number of Argument Error

Hello, I was following the video and encounter the following error...

Failures:

1) Editing todo items is successful when marking a single item complete Failure/Error: click_link "Mark Complete" ArgumentError: wrong number of arguments (2 for 1) # ./app/controllers/todo_items_controller.rb:49:in complete' # ./spec/features/todo_items/complete_spec.rb:11:inblock (3 levels) in <top (required)>' # ./spec/features/todo_items/complete_spec.rb:10:in `block (2 levels) in <top (required)>'

Finished in 0.31283 seconds 1 example, 1 failure

Can you see the problem..? I thought it was a problem with Syntax so I carefully check the "end"s but it still produces the same error.

Please help!

thank you :)

4 Answers

I had the same issue. The error actually gives you the line where we both messed up. ":49" in your case.

@todo_item.update_attributes(:completed_at, Time.now)

Should be:

@todo_item.update_attribute(:completed_at, Time.now)

My development environment (Atom) automatically filled out "update_attributes" instead of "update_attribute".

That's a great spot! Hope it works!

Hi there,

We're going to need to see some code, I think!

The test is in complete_spec.rb and the code being tested is in todo_items_controller.rb - can you post the code for those, please?

Steve.

Ki Bum Kim
Ki Bum Kim
1,520 Points

Hi Steve, Thanks for your response. Here is my code. for

complete_spec.rb
------------------------------------------------------------------------
require 'spec_helper'

describe "Editing todo items" do 
let!(:todo_list) { TodoList.create(title: "Grocery list", description: "Groceries")}
let!(:todo_item) { todo_list.todo_items.create(content: "Milk")}

 it "is successful when marking a single item complete" do
    expect(todo_item.completed_at).to be_nil
    visit_todo_list todo_list
    within dom_id_for(todo_item) do
        click_link "Mark Complete"
    end
    todo_item.reload
    expect(todo_item.completed_at).to_not be_nil
    end
end

--------------------------------------------------------------------------

and

todo_items_controller.rb
---------------------------------------------------------------------------
class TodoItemsController < ApplicationController
  before_action :find_todo_list 
  def index

  end

  def new
    @todo_item = @todo_list.todo_items.new
    end

    def create
        @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

  def edit
      @todo_item = @todo_list.todo_items.find(params[:id])
  end

  def update
      @todo_item = @todo_list.todo_items.find(params[:id])
      if @todo_item.update_attributes(todo_item_params)
        flash[:success] = "Saved todo list item."
        redirect_to todo_list_todo_items_path
      else
        flash[:error] = "That' todo item could not be saved."
        render action: :edit
      end
    end

    def destroy
      @todo_item = @todo_list.todo_items.find(params[:id])
      if @todo_item.destroy
        flash[:success] = "Todo list item was deleted."
      else
        flash[:error] = "Todo list item could not be deleted."
      end
      redirect_to todo_list_todo_items_path
    end

  def complete
  @todo_item = @todo_list.todo_items.find(params[:id])
  @todo_item.update_attributes(:completed_at, Time.now)
  redirect_to todo_list_todo_items_path, notice: "Todo item marked as complete."
  end

  def url_options
    { todo_list_id: params[:todo_list_id] }.merge(super)
  end

  private
  def find_todo_list
    @todo_list = TodoList.find(params[:todo_list_id])
  end

  def todo_item_params
    params[:todo_item].permit(:content)
  end

end

The only thing I can see is a possible lack of brackets on line 10 (I think!) of the spec code.

Try changing what you have, visit_todo_list todo_list to have some brackets like: visit_todo_list(todo_list)

I hope that either fixes the problem or makes the error more descriptive so we can track down what's wrong more easily.

Steve.