Working in an app where a page_title method was defined in application_helper.rb as such:
def page_title(title = nil)
if title.present?
content_for(:page_title) { "#{title} - SomeDomain.tld" }
else
content_for?(:page_title) ? content_for(:page_title) : "SomeDomain.tld"
end
end
In a view I need to pass this page_title on into some various links, example:
= link_to "http://www.some_bookmark_site.com/submit?url=#{URI::escape(request.url)}&title=#{URI::escape(page_title)}", :target =>"_blank" do
However when I do this I am getting a nil error "undefined method 'each_byte' for nil:NilClass" which indicates obviously the method’s returning a nil…
or is it that I need to pass a var in here instead? Would appreciate clarification on how to form this all properly for such conditions.
Full trace: http://pastebin.com/gegDETUp
Just wanted to note that I’m still looking for an answer on this question.
when i understand your question correctly, you are asking why your
page_titlemethod returnsnil?if that’s the case, you should have a look at how to use
content_forandyieldwithin templates:http://guides.rubyonrails.org/layouts_and_rendering.html#understanding-yield