I've looked at these posts on stack overflow: A concise explanation of nil v. empty v. blank in Ruby on Rails Rails: How do I check if a column has a value?
And I've tried out some different ways to check a record's existence, but my code is still throwing an error:
undefined method `links' for nil:NilClass
I have this is application_controller:
def header_links_when_signedin
if signed_in?
@header = @current_group.navbars.where(:header => true, :signedin => true).first
unless @header.links.first.blank?
@header.links
end
end
end
And I get the error on this line:
unless @header.links.first.blank?
Or anywhere I include links
when I have not previously created a link for the navbar I am calling.
Everything works fine when I have created the fields, I'm just covering the use case for when a link for a navbar has not been created yet for a group.