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

  • Home
  • SEARCH
  • 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 8684915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:25:39+00:00 2026-06-12T22:25:39+00:00

I have an app that allows users to enter, edit and search for projects

  • 0

I have an app that allows users to enter, edit and search for projects in a database.

In my search function, you can do complex searches by adding params to the search.

def self.like(text); "%#{text}%"; end

  def self.search(search_archive, search_client, search_status, search_fullname)
    # start with a scoped query, to apply more scopes on it afterwards
    _projects = Project.scoped 
    # then, for each of the parameters, apply the scope only if present

    if search_archive.present?
      _projects = _projects.where ['archive LIKE ?', like(search_archive)] 
    end
    if search_client.present?
      _projects = _projects.where ['client LIKE ?', like(search_client)] 
    end

     if search_status.present?
      _projects = _projects.where ['status LIKE ?', like(search_status)]
    end

if search_fullname.present?
      _projects = _projects.where ['fullname LIKE ?', like(search_fullname)]
    end
    # now you have applied only the present scopes. return the result, and watch 
    # the query as it executes.

    _projects

  end

Now I recently added the option to archive the project, that goes into the project table as a boolean.

I know my search function is wrong as I don’t think I can deal with booleans they way I have tried.

if search_archive.present?
          _projects = _projects.where ['archive LIKE ?', like(search_archive)] 
        end

Here is the error:

PG::Error: ERROR:  operator does not exist: boolean ~~ unknown
LINE 1: SELECT COUNT(*) FROM "projects"  WHERE (archive LIKE '%{"{:c...

Any ideas? Thanks in advance.

UPDATE:

Changing to the suggestion below,

if search_archive.present?
  _projects = _projects.where(:archive => search_archive)
end

I get this error:

PG::Error: ERROR:  missing FROM-clause entry for table "archive"
LINE 1: SELECT COUNT(*) FROM "projects"  WHERE "archive"."{:class=>"...
                                               ^
: SELECT COUNT(*) FROM "projects"  WHERE "archive"."{:class=>""archive""}" = '1'

Here is my search action:

def search


    @search = params[:archive], params[:client], params[:status], params[:fullname]

    @project_search = Project.search(*@search).order(sort_column + ' ' + sort_direction).paginated_for_index(per_page, page)

    @search_performed = !@search.reject! { |c| c.blank? }.empty? 

  @project = Project.new(params[:project])


respond_to do |format|
      format.html # search.html.erb
      format.json { render :json => @project }
    end

end 

ADDING PART OF SEARCH VIEW

<%= form_tag search_path, method: :get do %>

<% if current_user.try(:admin?) %>
Archive:
<%= check_box :archive, :class => "archive" %></H2>
<% end %>
<% if !current_user.try(:admin?) %>
<%= hidden_field :archive, :value => false %>
<% end %>

<div class="client">
Client : 
<%= select(@projects, :client, Project.order("client").map{|p| [p.client]}.uniq, :prompt => "-Any-", :selected => params[:client]) %></br>
</div>

<div class="buttons">
<div id="search_button">
<%= submit_tag "Search", name: nil, :class => "button" %>
</div>

<% end %>

EXPLANATION

If I am an Admin, and I leave the archive check box unchecked, I want to see all projects that aren’t archived. If I check it, I only want to see the archived ones, included with other params I search on.

If I am a normal user, I shouldn’t be able to see the archive checkbox, and every search I do should be on projects that have archive false, behind the scenes.

  • 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-12T22:25:40+00:00Added an answer on June 12, 2026 at 10:25 pm

    if archive is Boolean add something like follwing

    if search_archive.present?
      _projects = _projects.where(:archive => search_archive != "false")
    end
    

    Change

    <% if current_user.try(:admin?) %>
    Archive:
    <%= check_box :archive, :class => "archive" %></H2>
    <% end %>
    <% if !current_user.try(:admin?) %>
    <%= hidden_field :archive, :value => false %>
    <% end %>
    

    To

    <% if current_user.try(:admin?) %>
      Archive: <%= check_box_tag :archive, true, false, :class => "archive" %></H2>
    <% else %>
      <%= hidden_field :archive, :value => false %>
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an app that allows users to enter a project into a database.
I have an app that allows users to upload large data files and then
I have an iPhone app that allows users to record videos and I'd like
I have a topics app that allows users to create topics. For each individual
We have a WPF app that allows our users to download encrypted content and
I'm creating a web app that allows users to enter a number of colors,
I have an app that allows users to win prizes. To win a prize
I have a relatively simple web app, that allows the user to enter two
I have a web app that only registered users can use, therefore I should
I have an app that allows the user to choose an image, at design

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.