Reputation: 765
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
Reputation: 765
http://www.reddit.com/r/ruby/comments/fyprk/rails_beginner_needing_help_with_setting_a_cookie/
A kind redditor answered my question.
Upvotes: 3