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 4254954
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:09:13+00:00 2026-05-21T05:09:13+00:00

I have a controller set as the root of my app. It accepts in

  • 0

I have a controller set as the root of my app. It accepts in a parameter called uid and checks to see if the user exists. If not, I want it to redirect to the new user page and pre-populate the uid field with the uid in the parameter.

In my root_controller:

def index
  if params[:uid]
    @user = User.find_by_uid(params[:uid])
    if (!@user.blank?)
      # do some stuff
    else
      session[:user_id] = params[:uid]
      redirect_to(new_user_path, :notice => 'Please register as a new user')
    end
  else
    # error handling
  end
end

In my users_controller, GET /users/new action:

def new
  @user = User.new
  @user.uid = session[:user_id]
  # standard respond_to stuff here
end

This all works fine, but is this an acceptable way to do this? I originally tried passing the uid in the redirect statement, like:

redirect_to(new_user_path, :notice => 'Please register as a new user', :uid => params[:uid])

or even testing it with:

redirect_to(new_user_path, :notice => 'Please register as a new user', :uid => 'ABCD')

but neither seemed to pass the value to users_controller…I couldn’t access it using params[:uid] from that controller.

Is session a proper place to store stuff like this, or is there a better way to pass it via the redirect? Thanks!

  • 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-21T05:09:14+00:00Added an answer on May 21, 2026 at 5:09 am

    A session is fine to store that kind of information. Depending on what you are doing with the uid it might actually be dangerous to allow it to be read from the URL. Imagine if the end user was malicious and started putting other user’s IDs into there.

    For messages that should only last until the next request Rails actually has the flash object which will carry it over for you.

    http://guides.rubyonrails.org/action_controller_overview.html#the-flash

    That said, if you want to redirect to a url and pass some params, do so like this:

    redirect_to(new_user_path(:notice => 'Please register as a new user', :uid => 'ABCD'))
    

    The params you want to pass are arguments to the new_user_path method, not the redirect_to method.

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

Sidebar

Related Questions

I have a HTML form, and I have a Controller Action that accepts the
I have a root view controller which contains an outlet for my login view
I have standard servlet-mapping for Dispatcher Servlet - /app/* . I have controller that
I have the following methods in my controller: def create @user = User.new(params[:user]) if
When submitting one form from view, how can i also read or have controller
I have a controller with an action method as follows: public class InventoryController :
I have a controller action that is being executed by a link that was
I have a controller action which I would like to call another controller action.
I have multiple controller actions that takes an id public ActionResult Get(int? id) {
Say I have a controller with an Index Method and a Update Method. After

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.