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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T13:54:38+00:00 2026-05-20T13:54:38+00:00

Trying to build a search on my homepage with simple_form (Pretty much same as

  • 0

Trying to build a search on my homepage with simple_form (Pretty much same as formtastic). The search works fine and im getting my results but after submission I want to retain the vales with what the user submitted.

I am using a namespace for my form so how can I retain the data for the form. Here is some code which may help.

Controller

def index
  @results = Property.search(params[:search])
end

View

%h1 Search Form
= simple_form_for(:search) do |f|
    = f.input :location, :as => :select, :collection => Location.all.asc(:name)
        = f.input :type, :collection => PropertyType.all.asc(:name)
        = f.input :bedrooms, :collection => 1..10,
    %p.box
        = f.button :submit

-if @results
    %h1 Search Results
    .results
        - @results.each do |property|
            .result
                %h1= property.title

Within the Index controller I have tried all sorts of things ie

@search = params[:search]

But each time I try something the search breaks.

What am I doing wrong ?

Hope you can advise

  • 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-20T13:54:39+00:00Added an answer on May 20, 2026 at 1:54 pm

    One approach is to do as Xavier Holt suggested, and pass in values to each input. The simpleform doco suggests:

     = f.input :remember_me, :input_html => { :value => '1' }
    

    The other approach is to have simpleform do it for you. SimpleForm will automatically populate the fields with values if you give it something like an activerecord object.

    In this case, that means creating a model object:

    class PropertySearchCriteria
      attr_accessor :location, :type, :bedrooms
      def initialize(options)
        self.location = options[:location]
        self.type = options[:bedrooms]
        self.bedrooms = options[:bedrooms]
      end
    end
    

    Then, change your controller:

    def index
      @property_search_criteria = PropertySearchCriteria.new(params[:search])
      @results = Property.search(@property_search_criteria)
    end
    

    (you’ll have to change the Property.search method as well)

    Then, change your simple_form_for:

    = simple_form_for(:search, @property_search_criteria) do |f|
    

    And if you do all that, and get the stars to align just right, then simpleform will pre-populate the form fields all by itself. You may have to add some stuff to PropertySearchCriteria to get simpleform to be properly happy.

    This is a lot of stuffing around just to get the values showing up, but it’ll keep you sane if you need to add validations.

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

Sidebar

Related Questions

I'm trying to build a search page using LINQ to Entities, but the following
I am trying to build in a search box on a results page in
I'm trying to build a search for our internal support database - each support
I am trying to build a search engine using java and the lucene API
I was trying to build a 'site search' on a simple http site. I
I'm trying to build an android app that would do a local search on
I'm trying to build a local version of the freebase search api using their
I was trying Build For Archiving application (from Titanium Mobile) with xCode 4.4, but
I'm trying to build a search that is similar to that on Google (with
I am trying to build an advance search option for our website. I am

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.