views:

20

answers:

1

I'm working on Ruby on rails 2.3.2 and I'd like to keep the search text through postback so I can populate it after that.

Right now, the search page is called by a method called "search" on a controller. Once the search is done I render the file this way:

render :file => '/search/index', :layout => true, :use_full_path => true

I'd like to save the search on a session like this:

session[:text_to_search] = params[:txtSearch]

and then assign its value back to the textbox. The textbox is actually an html input type="text".

How can I do that?

+1  A: 

note that since you are rendering the page as opposed to redirecting to a new page you can still access the params from in that page...

<%= text_field_tag :txtSearch, params[:txtSearch] %>

should work.

if you insist on using the session then:

<%= text_field_tag :txtSearch, session[:text_to_search] %>
emh
Thanks. I have an issue though. I have set the text field to show some text if it's empty, and also I've set a default value like "Type the text to search here". So, if I don't take that out it will show this text, not the one I searched. So, how can I check whether params[:text_to_search] is empty or not so I can set its value = "type the text to search..." only when params[:text_to_search] is empty?
Brian Roisentul
<%= text_field_tag :txtSearch, params[:text_to_search].blank? ? "Default text" : params[:text_to_search] %>
emh