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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T14:47:39+00:00 2026-05-10T14:47:39+00:00

Here’s a simplified version of what I’m trying to do : Before any other

  • 0

Here’s a simplified version of what I’m trying to do :

  1. Before any other actions are performed, present the user with a form to retrieve a string.
  2. Input the string, and then redirect to the default controller action (e.g. index). The string only needs to exist, no other validations are necessary.
  3. The string must be available (as an instance variable?) to all the actions in this controller.

I’m very new with Rails, but this doesn’t seem like it ought to be exceedingly hard, so I’m feeling kind of dumb.

What I’ve tried : I have a before_filter redirecting to a private method that looks like

def check_string   if @string     return true   else     get_string   end end 

the get_string method looks like

def get_string   if params[:string]     respond_to do |format|       format.html {redirect_to(accounts_url)} # authenticate.html.erb     end   end    respond_to do |format|     format.html {render :action =>'get_string'} # get_string.html.erb   end end 

This fails because i have two render or redirect calls in the same action. I can take out that first respond_to, of course, but what happens is that the controller gets trapped in the get_string method. I can more or less see why that’s happening, but I don’t know how to fix it and break out. I need to be able to show one form (View), get and then do something with the input string, and then proceed as normal.

The get_string.html.erb file looks like

<h1>Enter a string</h1> <% form_tag('/accounts/get_string') do %> <%= password_field_tag(:string, params[:string])%> <%= submit_tag('Ok')%> <% end %> 

I’ll be thankful for any help!

EDIT

Thanks for the replies…
@Laurie Young : You are right, I was misunderstanding. For some reason I had it in my head that the instance of any given controller invoked by a user would persist throughout their session, and that some of the Rails magic was in tracking objects associated with each user session. I can see why that doesn’t make a whole lot of sense in retrospect, and why my attempt to use an instance variable (which I’d thought would persist) won’t work. Thanks to you as well 🙂

  • 1 1 Answer
  • 1 View
  • 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. 2026-05-10T14:47:39+00:00Added an answer on May 10, 2026 at 2:47 pm

    Part of the problem is that you aren’t setting @string. You don’t really need the before_filter for this at all, and should just be able to use:

    def get_string   @string = params[:string] || session[:string]    respond_to do |format|     if @string         format.html {redirect_to(accounts_url)} # authenticate.html.erb     else        format.html {render :action =>'get_string'} # get_string.html.erb     end   end end 

    If you want the @string variable to be available for all actions, you will need to store it in the session.

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

Sidebar

Related Questions

Here is my code, which takes two version identifiers in the form 1, 5,
Here's a problem I ran into recently. I have attributes strings of the form
Here is the scenario: I'm writing an app that will watch for any changes
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Here's what I'm trying do to in a single SQL Server procedure: @ID1 int
Here is a snippet of my form <form action= method=post onsubmit=return verify()> <input type=submit
Here's a basic regex technique that I've never managed to remember. Let's say I'm
Here is the issue I am having: I have a large query that needs
Here's my scenario - I have an SSIS job that depends on another prior
Here is a simplification of my database: Table: Property Fields: ID, Address Table: Quote

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.