Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3876952
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:26:29+00:00 2026-05-19T22:26:29+00:00

In my Rails app, if the user is trying to create a new account,

  • 0

In my Rails app, if the user is trying to create a new account, and already has a session going (i.e. is logged in), I want to display a message that says “It looks like you already have an account”.

To do this, I’m trying to check for a current session with the following code:

<% if session[:user_id]? %>
<div id="error_expanation">Seems like you already have an account with us.
  <% link_to "Sign in now", login %></div>
<% end %>

However, this code results in the following error:

compile error
/path/to/app/views/users/_form.html.erb:17: syntax error, unexpected ';'
');@output_buffer.safe_concat('     ...
   ^
/path/to/app/views/users/_form.html.erb:42: syntax error, unexpected kENSURE, expecting $end

I’m pretty sure is the ‘session[:user_id]?’ that’s causing the problem, because if I replace it with something from another if statement, it works.

Any idea on what I need to fix to check for this? Thanks!

Oh, and here’s my sessions_controller.rb if it’s needed:

class SessionsController < ApplicationController

  def edit
    session[:return_to] = request.referer
  end

  def new
  end

  def create
    if user = User.authenticate(params[:email], params[:password])
      session[:user_id] = user.id
      session[:user_name] = user.name
      redirect_to admin_url
    else
      redirect_to login_url, :alert => "Invalid username / password combination"
    end
  end

  def destroy
    session[:user_id] = nil
    redirect_to admin_url, notice => "You've successfully logged out."
  end  

end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T22:26:30+00:00Added an answer on May 19, 2026 at 10:26 pm

    I would suggest changing this line:

    <% if session[:user_id]? %>
    

    to

    <% if session[:user_id] %>
    

    That should fix the problem. The cleaner solution would be to add a function call to your application controller like this:

    class ApplicationController
      def user_is_logged_in?
        !!session[:user_id]
      end
    end
    

    Then you could do the following:

    <% if user_is_logged_in? %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a Backbone.js/Rails app and I'm trying to create a new object through
I'm trying to create a User model for my Ruby on Rails app that
I'm writing a rails app that has a model called 'User' and a model
I want to integrate chargify to my rails app. I have user object and
Having trouble framing this assertion in Rspec for my rails app. A User has
I'm trying to nest some routes under the namespace, account. I want user management
I'm using the json_spec gem in a Rails app and I'm trying to create
Hello I trying to create a reset password for my rails app; but when
I'm trying to create a user acount on my rails backend via json from
In my first rails app I'm trying to use form_for and fields_for to create

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.