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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:48:23+00:00 2026-06-15T23:48:23+00:00

I currently have a table sorted/filtered by several select boxes and two radio buttons,

  • 0

I currently have a table sorted/filtered by several select boxes and two radio buttons, and it is working fine. I would the select boxes to be automatically populated from a table. Specifically, I would like a state select box that is populated from the States in my Articles table. I currently have an articles.rb model and state.rb model, and I have the relationships set up. article belongs_to :state, state has_many :article. Here is my code so far:

index.html.erb

<%= form_tag articles_path, :method => "GET" do %>

  <%= radio_button_tag :gender_search, "M" %>
  <%= label_tag :gender_search_M, "M" %>
  <%= radio_button_tag :gender_search, "F" %>
  <%= label_tag :gender_search_F, "F" %>

  <%= select_tag :state_search, options_for_select([['Select a state', 0],['-----------', 0],['LA', 'LA'],['MS', 'MS'], ['TX', 'TX']], @prev_state) %>
  <%= select_tag :city_search, options_for_select([['Select a city', 0],['----------', 0],['Mandeville', 'Mandeville'],['Covington', 'Covington']], @prev_city) %>

  <%= submit_tag "Go" %>

<% end %>
<table class="table table-striped table-bordered span8 table-condensed" id="articles_table">
  <thead class="header">
    <tr>
      <th>ID</th>
      <th>Title</th>
      <th>Description</th>
      <th>Created_At</th>
    </tr>
  </thead>
  <tbody>
    <%= render @articles %>
  </tbody>
</table>

_article.html.erb

<tr>
  <td> <%= article_counter +1 %> </td>
  <td> <%= article.Title %> </td>
  <td> <%= article.Description %> </td>
  <td> <%= article.Created_At %> </td>
</tr>

article.rb

class Article < ActiveRecord::Base
  belongs_to :state


def self.city_search(city_search)
    if city_search
      where('City LIKE ?', "%#{city_search}%")
    else
      scoped
    end
end
def self.state_search(state_search)
    if state_search
      where('State LIKE ?', "%#{state_search}%")
    else
      scoped
    end
end

Please let me know if I need to post any more code or any more information. Anything that could help me would be great.

  • 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-15T23:48:24+00:00Added an answer on June 15, 2026 at 11:48 pm

    After looking at this website:
    http://apidock.com/rails/ActionView/Helpers/FormOptionsHelper/collection_select

    I figured out that I actually did not need to have models set up for State and City. All I needed to do was make a collection_select that selected the Distinct States from my Articles table. Here is what it looks like:

    <%= collection_select :article, :state, Article.select(:state).uniq.order('state ASC'), :state, :state, {:prompt => 'Select a State'},{:name => "state_search"} %> 
    

    So all I had to do was set up the collection_select like the website said and add Article.select(:state).uniq.order(‘state ASC’) as my collection to select the uniq states from my Articles table.

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

Sidebar

Related Questions

I currently have a working table that is sorted by several select boxes. I
I currently have a Table [org.eclipse.swt.widgets.Table] with several TableColumns; however, due to UI space
Currently I have two tables I have select-all functions on the top left checkboxes,
I have a table that is to be sorted based on two columns of
I currently have a table of concentrations, which are linked to a table of
I currently have a table and in one of the <td> , I have
I currently have a table structure that looks something like this(some details omitted): ColumnName
I currently have a table with a nested table in it: <table class=datagrid id=report>
I currently have a table which only has a single editable column. I have
I currently have a table with an id column that is being autoincremented and

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.