TemplateError: wrong number of arguments in default_url_options()

Posted Posted by Wes in Ruby on Rails     Comments No comments
Jan
30

During an app upgrade to Rails 2.2.2, I came across this error that baffled me for a few minutes:

ActionView::TemplateError
    (wrong number of arguments (0 for 1)) on line #34
    of app/views/account/_dashboard_header.rhtml:

34: <%= link_to 'My Dashboard', my_dashboard_url >

Checking out the backtrace:

(eval):3:in `default_url_options'
(eval):3:in `my_dashboard_url'
app/views/account/_dashboard_header.rhtml:34

Confusing. Why would this named route suddenly stop working? I did a search for default_url_options and found that I had overridden that function:

if production_mode?
  def default_url_options()
    { :protocol => 'https://' }
  end
end

Aha! Back in the day, default_url_options didn’t have any default options, so I wasn’t bothering to merge my desired options with the options parameter. I fixed it with a reverse_merge so any passed-in options would still exist.

Post comment

about databasically

We live and work in Kansas City, USA.

We're passionate about helping small businesses succeed and want to help you use technology to get more done.

From server, desktop, network management to programming custom web applications in Ruby on Rails, we're here to lend a hand.

Contact us if you have any questions!