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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:51:30+00:00 2026-05-17T00:51:30+00:00

This works: Baseline Controller @search = Baseline.search(params[:search]) @baselines = @search.paginate :page => params[:page], :per_page

  • 0

This works:

Baseline Controller

@search = Baseline.search(params[:search])

@baselines = @search.paginate :page => params[:page], :per_page => params[:per_page]

baseline index view

<% form_for @search do |f| %>
  <%= f.text_field :baseline_name_like_or_description_like %>
  <%= submit_tag 'Search' %>
<% end %>

Where would I trim the leading and trailing whitespace in the text_field? Could I use a .strip! somewhere?

  • 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-17T00:51:30+00:00Added an answer on May 17, 2026 at 12:51 am

    Nick, surprisingly, it’s quite difficult to find information on advanced Searchlogic techniques. Sanitization has been particularly difficult for me to deal with.

    Here’s a pretty nifty (and quick) way to deal with your issue.

    controller

    stays the same

    views/baselines/index.html.erb

    <% form_for @search do |f| %>
      <%= f.text_field :keywords %>
      <%= submit_tag 'Search' %>
    <% end %>
    

    models/baseline.rb

    class Baseline < ActiveRecord::Base
      scope_procedure :keywords, lambda { |query|
        baseline_name_like_or_description_like(query.strip)
      }
    end
    

    Extras

    I’m excited to share the other cool things I’ve learned with Searchlogic, so I’ll share them here.

    First, with very little work, you can power-up that keywords scope_procedure with minimal effort.

    scope_procedure :keywords, lambda { |query|
      baseline_name_like_any_or_description_like_any(query.strip.split(/\s+/))
    }
    

    Note the addition of the any operator to each named_scope

    This will allow you to enter searches like “foo bar” and it will match baseline_names like “i can foo haz bar” or “bar time, foo!” This would even match a Baseline if the name was “foo” and the description was “bar”; point being, you get tons of extra control if you use scope_procedure instead of a predefined named_scope in your Searchlogic forms.

    Second, you can sanitize your search forms with a little extra effort. This one took quite a while to figure out, but I decided to create a subclass of the Searchlogic::Search class.
    Check it out:

    models/baseline_search.rb

    class BaselineSearch < Searchlogic::Search
      def initialize(params, klass, current_scope)
    
        allowed_params = [:keywords, :name_like_any, :foo_equals, :order]
    
        conditions = {}
    
        for x in allowed_params 
          conditions[x] = params[x] unless params[x].blank?
        end
    
        super(klass, current_scope, conditions)
      end
    end
    

    If you’re wondering where I found that initialize method signature, check Searchlogic::Search

    Now, instead of invoking Searchlogic::Search on your model, you need to create a simple override in your baseline.rb. Here, we’ll implement our own Searchlogic::Search::Implementation

    models/baseline.rb

    class Baseline < ActiveRecord::Base
    
      # cool scope procedures
      # ...
    
      def self.search(params={})
        BaselineSearch.new(params || {}, self, scope(:find))
      end
    end
    

    Now, when you call Baseline.search(params[:search]), it will invoke a new BaselineSearch instead of the Searchlogic::Search default. The cool thing here is, if you want to skip using your BaselineSearch, you can call Baseline.searchlogic(params[:search]) to use the Searchlogic default instead.

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

Sidebar

Related Questions

This works view layout [ image load http://i2.ytimg.com/vi/e3wShd_bX8A/default.jpg ] But this doesn't view layout
This works (prints, for example, 3 arguments): to run argv do shell script echo
This works, but is it the proper way to do it??? I have a
This works just fine: protected void txtTest_Load(object sender, EventArgs e) { if (sender is
This works fine: $.getJSON(http://localhost:59396/xxxWeb/ CarouselHandler.ashx?action=getproducts&ids= + ids, function(data) { carousel.size(allProductIDs.length); if (numberOfImagesLeftToShow < numberOfImagesToDisplay)
This works: Tweener.addTween( [ _fee, _fye, _fum ] , { alpna:1, time:10 }); But
This works perfectly if the priobann list is populated: banns << priobann?.pop() However, if
This works: class ButtonCountObserver { private var cnt = 0 // private field def
This works: #include <iostream> using namespace std; but this fails: #include <stdio> When is
This works: var.replace(/[^0-9]+/g, ''); That simple snippet will replace anything that is not a

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.