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

  • Home
  • SEARCH
  • 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 9137749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:09:58+00:00 2026-06-17T09:09:58+00:00

I am trying to redirect depending on a value in the database. for example

  • 0

I am trying to redirect depending on a value in the database.

for example if a technician is logged in they should be redirected to site A else everyone else should be redirected to site B.

my attempt so far looks as follows

  def create
    @user_session = UserSession.new(params[:user_session])
    @user = User.new(params[User.where(:username => @user_session.username)])
    #@user = UserUser.where(:username => @user_session.username)
    #@user = User.select("tech").find(@user)
    #@user = User.new
    respond_to do |format|
      if @user_session.save
        if @user.tech == 1
          format.html { redirect_to '/tech/index', notice: 'Login Successful A Company' }
        else
          format.html { redirect_to :users, notice: @user.tech }
        end
      else
        format.html { render action: "new" }
      end
    end
  end 

The problem is that the if statement always resolves to the code in the else statement instead of the code above the else statement. In this case the @user.tech is nil I am somehow not pointing at the data in the database

  • 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-06-17T09:09:59+00:00Added an answer on June 17, 2026 at 9:09 am

    Ok

    Try changing this line

    @user = User.new(params[User.where(:username => @user_session.username)])
    

    Here you do something strange, and I think you should get an error message. @user is just a new instance of the User model in memory

    I think you need this

    @user = User.where(:username => @user_session.username)]).first
    

    But, if the user name is not unique, this is a security problem. A admin can have the same name as a user So you should do something like

    @user = User.where(:id => @user_session.user_id)]).first
    

    tech? method in user.rb ( the model )
    I am guessing tech either 1 or 0 in the database?

    class User
        def tech?
          tech == 1 #
        end
    end
    

    Now you can do

    @user.tech?
    

    And it will return ture or false

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to redirect ALL requests for mydomain.com whether they are something like:
im trying to redirect users to another page if they are using internet explorer
OBJECTIVE I'm trying to accomplish an automatic redirect depending on the users language. I
Im trying to redirect this, example.com/ slide?page=4 to example.com/ slide/issue43?page=4 But it cannot effect
Im trying to redirect pages such as: /selected-work/project-name-1 /selected-work/project-name-2 /selected-work/project-name-3 /selected-work/category/category-name to just /work/
I'm trying to redirect this page Page to a Jquery mobile website that I'm
I've been trying to redirect my subdomain buynow.mydomain.info to the product link which is
I'm trying to redirect a few pages to a new domain and I have
We've been trying to redirect from one action to another, hoping that data would
I am trying to redirect pages using mod_rewrite to the pages with some variables

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.