The empty?
method is undefined for nil class, so when you try nil.empty?
in the console it gives: undefined method empty? for nil:NilClass
I created this method in my application_helper.rb:
def full_title(page_title)
base_title = "my app"
if page_title.empty?
base_title
else
"#{base_title} - #{page_title}".html_safe
end
end
In my application layout I call it on the title tag like this:
!!!
%html
%head
%title #{full_title(yield(:title))}
...
...
%body
= yield
And in each of my views I add provide(:title, "something")
for passing a string to this helper method.
But when I don't use provide(:title, "something")
it looks like if page_title.empty? returns true!
My question is why page_title.empty? returns true. I think the page_title variable is nil when I don't use provide(:title, "something")
, does it not raise any errors? such as undefined undefined method empty? for nil:NilClass