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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:46:43+00:00 2026-06-12T21:46:43+00:00

I’m having a problem with a check_box_tag that I am using when trying to

  • 0

I’m having a problem with a check_box_tag that I am using when trying to search for archived projects in a table.

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

So if the user isn’t an admin, archive is always false.

If the user is an admin, then archive is always false, unless they check the checkbox.

When the check box is checked, and a search is submitted, the results are shown, but the box becomes unchecked again. Is there a way to check it checked? I tried using :selection => params[:archive] but that didn’t seem to work. Thanks in advance.

Adding search function

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

  def self.search(search_archive, search_client)
    _projects = Project.scoped 


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


    _projects

  end


end

Search action:

def search

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

    @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 

URLS:

When I search for Client: Test, which archived checked:

http://localhost:3000/search?utf8=%E2%9C%93&%5Bclient%5D=Test&%5D=&archive=true&per_page=10

No projects are found which is correct, now I unclick archived:

http://localhost:3000/search?utf8=%E2%9C%93&%5Bclient%5D=Test&%5D=&archive%5B%7B%3Avalue%3D%3Efalse%7D%5D=&per_page=10

Which again shows the correct results, but the box is now checked, but should be unchecked, incase I want to refine the search

Fix:
In my search function:

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

In my search view:

<% if current_user.try(:admin?) %>
  Archive: <%= check_box_tag :archive, true, !!params[:archive], :class => "archive" %></H2>

<% end %>
  • 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-12T21:46:45+00:00Added an answer on June 12, 2026 at 9:46 pm

    Change

    <%= check_box_tag :archive, true, false, :class => "archive" %>
    

    To

    <%= check_box_tag :archive, true, !!params[:archive], :class => "archive" %>
    

    Ref check_box_tag for more information

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the

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.