Update: The problem below occurs when I add:
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
I’m trying to redirect to a landing page after the user has logged in but the variables I set in application_controller.rb are not reflected in the page I redirect to.
My sessions_controller.rb looks like this:
def create
user = User.find_by_email(params[:email])
if user && user.authenticate(params[:password])
session[:user_id] = user.id
redirect_to '/landingpage', :notice => "Logged in!"
My application.html.erb looks like this
<!DOCTYPE html>
<html>
<head>
<%= yield :head %>
</head>
<body>
<%= yield :body1%>
</body>
My view for landing page looks like this:
<% content_for :head do %>
<% if current_user %>
<script>'function test(){alert('user is signed in')}'</script>
<% else %>
<script>'function test(){alert('user is not signed in')}'</script>
<% end %>
<% content_for :body1 do %>
<% if current_user %>
User is signed in
<% else %>
User is not signed in
<% end %>
<button onClick="test();">test</button>
<% end %>
The result: After signing in, the page displays “User is signed in” but the function still returns user is not signed in. However, if I click refresh in the browser, it loads everything properly.
I’m tring to understand why using redirect does not update the header info.
The problem had to do with jquery mobile, here is the solution that worked: