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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:11:51+00:00 2026-05-26T05:11:51+00:00

Intro: I am working on a Car dealer application so I have a table

  • 0

Intro:
I am working on a Car dealer application so I have a table named cars with fields carname_id and carmodel_id. carname_id and carmodel_id are taken from 2 tables named carnames and carmodels where I keep all car names and car models. Now I’ve setup these models so I can have them in a relation, something like belongs_to and has_many (not relevant cause this is working as it should be – I can add cars and models to a new car from a select list)

I am using meta_search to search by many fields and the code in the search_form looks like his

<%= f.label :make_contains, "Select Car Make" %>
<%= f.select :make_contains, Car::CAR_MAKE %>

<%= f.label :model_contains, "Select Model" %>
<%= f.text_field :model_contains, Car::CAR_MODEL %>

the make and model fields are the old fileds in the cars table that I used for storing the car and model name of a car. But when I get in to the advanced search form I found myself stuck in choosing dynamicaly the model list.. I have in car.rb a list of car names specified for Car list and a list for car models.. I agree that this is not the best way to do it, that’s why I had to create 2 tables: carnames and carmodels that I’ve told you about at the start.. I have setup everything and the add new car works as expected, I can select a carname_id from carnames table and carmodel_id from carmodels table and it is stored in database perfectly using a form like this:

<%= f.label :carname_id, "Car name:" %>
<%= f.select :carname_id, @select_carnames %>

<%= f.label :carmodel_id, "Model name:" %>
<%= f.select :carmodel_id, @select_carmodels %>

this way I give up on make and model fields from cars table as I have 2 new working fields carname_id and carmodel_id

Now to The Problem:
how can I make the search by carmodel_id and carname_id, when making a form like this one:

<%= f.label :carname_id_contains, "Model name:" %>
<%= f.select :carname_id_contains, @select_carnames %>
<%= f.label :carmodel_id_contains, "Model name:" %>
<%= f.select :carmodel_id_contains, @select_carmodels %>

returns me an error
undefined method `carname_id_contains’ for MetaSearch::Searches::Car:0xb584b7a4

cars controller:

def index
  @search = Car.search(params[:search])
  @cars = @search.all.paginate :page => params[:page], :per_page => 18
  @select_carnames = Carname.find(:all).map{|element| [element.name, element.id]}
  @select_carmodels = Carmodel.find(:all).map{|element| [element.name, element.id]}

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @cars }
      format.json { render :json => @cars.map(&:attributes) }
    end
  end



   def new
    @car = Car.new
    @select_carnames = Carname.find(:all).map{|element| [element.name, element.id]}
    @select_carmodels = Carmodel.find(:all).map{|element| [element.name, element.id]}
        5.times { @car.assets.build }

        respond_to do |format|
          format.html # new.html.erb
          format.xml  { render :xml => @car }
        end

  end

def edit
  @car = Car.find(params[:id])}
  @select_carnames = Carname.find(:all).map{|element| [element.name, element.id]}}
  @select_carmodels = Carmodel.find(:all).map{|element| [element.name, element.id]}}<br />
  5.times { @car.assets.build }
end

I hope I described it as good as possible and I really would apreciate any help and any ideas on this one. Thanks all for your time.

  • 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-26T05:11:51+00:00Added an answer on May 26, 2026 at 5:11 am

    and the answer is

    <%= f.label :carname_id_equals, "Model name:" %>
    <%= f.collection_select :carname_id_equals, Carname.order('name ASC').all,  :id, :name, :include_blank => true %><br />
    
    <%= f.label :carmodel_id_equals, "Model name:" %>
    <%= f.collection_select :carmodel_id_equals, Carmodel.order('name ASC').all, :id, :name, :include_blank => true %><br />
    

    I’ll need to read more the Rdoc in the future 🙂

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

Sidebar

Related Questions

Intro: I am working on a car dealer project.. sells every brand of cars
I have a table that is populated depending on how many cars are there.
I have a class Cars and class Models. Car has many properties such as
I'm working on a car dealer website at the moment, and I've been working
I'm working on some homework for an intro to C class, in which we
I'm working on some homework for an intro to C class, in which we
I'm working on a card game in C# for a project on my Intro
I have this simple example I can't seems to get working : MERGE INTO
I am working on integrating Assetic into an application that I am building. The
I'm working on a program from my C++ textbook, and this this the first

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.