title: Rails: Check for cookie
body: <p>I can't really find the exact information that solves this quite common problem. I want to set a cookie and if it is not possible (cookies are disabled) I want to show an error page.</p>
  
  <p>In my application controller I set the cookie with this:</p>
  
  <pre><code>  if (cookies[:user].blank?)
      cookies[:user] = {
        :value =&gt; (0...10).map{ ('a'..'z').to_a[rand(26)] }.join,
        :expires =&gt; 6.months.from_now,
        :domain =&gt; 'localhost'          
      }           
     end 
  </code></pre>
  
  <p>and then in my other controller Booking controller:</p>
  
  <pre><code>if cookies[:user].blank?
    @publish_form = false
    @no_cookies = true
  end
  </code></pre>
  
  <p>and in the view:</p>
  
  <pre><code>   &lt;% if @no_cookies %&gt;
  You need to enable cookies
  &lt;% end %&gt;
  </code></pre>
  
  <p>Now, this doesn't really work. It will create a cookie if cookies are enabled but if cookies are disabled it will still create a "cookie" so in my Booking Controller it will have a value and thus not be blank. If the page is reloaded it will create another cookie value. It seems like it is only creating a session or something. Using request.cookie doesn't work either.</p>
  
  <p>What should I use in order to create a cookie whenever a user enters the page, check if a cookie exist and show different views depending on whether a cookie exist or not?</p>