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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:01:20+00:00 2026-06-08T13:01:20+00:00

I am trying to search my postgresql db in rails. I followed the Railscasts

  • 0

I am trying to search my postgresql db in rails. I followed the Railscasts #111 Advanced Search tutorial and it is working for the name and category of my items column in plain text. However, I want to set a min/max price on my search as well which is where I come into my problem. In my db my price is stored as a string in the format “AU $49.95”. Can I convert this into a float on the fly in my scoped search? If so how? If not, what should I do?

Here is the code:

search.rb

class Search < ActiveRecord::Base
  attr_accessible :keywords, :catagory, :minimum_price, :maximum_price

    def items
      @items ||= find_items
    end

    private

    def find_items
      scope = Item.scoped({})
      scope = scope.scoped :conditions => ["to_tsvector('english', items.name) @@ plainto_tsquery(?)", "%#{keywords}%"] unless keywords.blank?
      scope = scope.scoped :conditions => ["items.price >= ?", "AU \$#{minimum_price.to_s}"] unless minimum_price.blank?
      # scope = scope.scoped :conditions => ["items.price <= ?", "AU \$#{maximum_price.to_s}"] unless maximum_price.blank?
      scope = scope.scoped :conditions => ["to_tsvector('english', items.catagory) @@ ?", catagory] unless catagory.blank?
      scope
    end

end

searches_controller.rb

class SearchesController < ApplicationController
  def new
    @search = Search.new
  end

  def create
    @search = Search.new(params[:search])
    if @search.save
      redirect_to @search, :notice => "Successfully created search."
    else
      render :action => 'new'
    end
  end

  def show
    @search = Search.find(params[:id])
  end
end

Thanks for reading this far!

  • 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-06-08T13:01:21+00:00Added an answer on June 8, 2026 at 1:01 pm

    Use the data type numeric or money for exact numerical calculation without rounding errors – and sorting as a number (not as text).
    Converting string literal to numeric should not be a performance problem at all.

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

Sidebar

Related Questions

I'm trying to search multiple fields. Something like this: [NSPredicate predicateWithFormat:@(name title contains[cd] %@)
Trying to get searching working on Heroku using partial search The following query generates
I'm trying to search the DB2 equivalent of generate_series() (the PostgreSQL-way of generating rows).
Im trying to search a item table, there is an id, name and oldId
I am trying to search through items in listview control in vb.net one by
Friends: in PostgreSQL plpython, am trying to do an iterative search/replace in a text
Trying to search through a column in a db, and pull out the total
Am trying to search the student details with their name or email or mobile.
I'm trying to search a document for data on a specific column. I am
While trying to search with id sorting (and paginating) im getting from the log:

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.