Hartl Chapter 5, Section 5.6, Exercise 4

I am still getting an error when running $bundle exec rake test:

ArgumentError: wrong number of arguments (0 for 1)
     app/helpers/application_helper.rb:2:in `full_title'

“On line 2, you need to pass exactly one argument. See http://ruby-doc.org/core-2.2.0/ArgumentError.html

Looking here: http://ruby-doc.com/docs/ProgrammingRuby/html/tut_methods.html I saw that a method with one argument looks like:

def myNewMethod(arg1, arg2, arg3)     # 3 arguments
  # Code for the method would go here
end

def myOtherNewMethod                  # No arguments
  # Code for the method would go here
end

def myOtherNewMethod(arg1)
end

So why am I still getting an error? My ‘app/helper/application_helper.rb file looks like this:

module ApplicationHelper
    def full_title(page_title)
     base_title = "Ruby on Rails Tutorial Sample App"
      if page_title.empty?
        base_title
          else
        " #{page_title} | #{base_title}"
      end
    end
end

So isn’t ‘def full_title(page_title)’ passing only one argument?


[July 11, 2015 – EDIT] I was able to figure out my error. I had to pass an argument through the full_title method:

def full_title(page_title = " ")
  base_title = "Ruby on Rails Tutorial Sample App"
  if page_title.empty?
    base_title
  else
    "#{base_title} | #{page_title}"
  end
 end

I had thought I did because of ‘(page_title)’ but (page_title) is different from (page_title = ” “). Since the title is a string that I am passing, I needed to set page_title equal to an empty string.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s