BasicObject
BasicObject

Reputation: 765

Use a link_to to set persistent cookie in Ruby on Rails

I would like to save a cookie with a visitor's browser using a link_to or a button. It's sole purpose is display a one time welcome message.

application_controller:

class ApplicationController < ActionController::Base
  before_filter :first_time_visiting?
  def first_time_visiting?
    if session[:first_time].nil?
      # session[:first_time] = 1
      redirect_to "pages#welcome"
    end
  end
end

Instead of automatically accepting the cookie like the commented code, I'd like to attach session[:first_time] = 1 to a link_to or a button_to in the pages#welcome view. I'm sure this is a simple task but I'm just wondering if I'm going about this correctly. Can I just use something like:

Pages#welcome:

<%= link_to("Continue", :controller => "home", :action => "index", :first_time => 1) %>

Thank you for reading my post.

Upvotes: 3

Views: 2422

Answers (1)

Related Questions