Skip to content

Instantly share code, notes, and snippets.

@vsername
Last active January 4, 2016 11:29
Show Gist options
  • Save vsername/8615139 to your computer and use it in GitHub Desktop.
Save vsername/8615139 to your computer and use it in GitHub Desktop.

Unable to check if first_time_visiting? inside an existing first_time_visiting?.

application_controller.rb

def first_time_visiting?
  return false if cookies[:first_visit]
  cookies[:first_visit] = 0
end
helper_method :first_time_visiting?

application.html.erb

<% if first_time_visiting? %>
  <%= render 'This works' %>

  <%= render 'shared/some_partial' %>
<% end %>

Error starts here

_some_partial.html.erb

<% if first_time_visiting? %>
  <%= render 'This doesn't work' %>
<% end %>

<%# Other unrelated ERB here %>

Working on a solution

toretore: set the cookie in an after_filter
frank_o: Basically I'm unable to check if first_time_visiting inside another if first_time_visiting
frank_o: after_filter you say
toretore: def first_time_visiting? !cookies[:touched]; end
toretore: after_filter :touch_cookie; def touch_cookie; cookies[:touched] ||= true; end

application_controller.rb

after_filter :touch_cookie

def touch_cookie
  cookies[:touched] ||= true
end
  
def first_time_visiting?
  !cookies[:touched]
end
helper_method :first_time_visiting?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment