before filter - in Rails : Retrieve user input from a form that isn't associated with a Model, use the result within the controller -


here's simplified version of i'm trying :

  1. before other actions performed, present user form retrieve string.
  2. input string, , redirect default controller action (e.g. index). string needs exist, no other validations necessary.
  3. the string must available (as instance variable?) actions in controller.

i'm new rails, doesn't seem ought exceedingly hard, i'm feeling kind of dumb.

what i've tried : have before_filter redirecting private method looks like

def check_string   if @string     return true   else     get_string   end end 

the get_string method looks

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

this fails because have 2 render or redirect calls in same action. can take out first respond_to, of course, happens controller gets trapped in get_string method. can more or less see why that's happening, don't know how fix , break out. need able show 1 form (view), , input string, , proceed normal.

the get_string.html.erb file looks

<h1>enter string</h1> <% form_tag('/accounts/get_string') %> <%= password_field_tag(:string, params[:string])%> <%= submit_tag('ok')%> <% end %> 

i'll thankful help!

edit

thanks replies...
@laurie young : right, misunderstanding. reason had in head instance of given controller invoked user persist throughout session, , of rails magic in tracking objects associated each user session. can see why doesn't make whole lot of sense in retrospect, , why attempt use instance variable (which i'd thought persist) won't work. :)

part of problem aren't setting @string. don't need before_filter @ all, , should able use:

def get_string   @string = params[:string] || session[:string]    respond_to |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 want @string variable available actions, need store in session.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -