Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Selecting Records Using collection_select and Using CSS for Formatting

Selecting Records Using collection_select and Using CSS for Formatting

Problem

I have the following collection_select logic in my Rails 3.2.3 form to Select States and order them by name.


I have a Country Model where the ID is in the State model. My User model has country_id and state_id. User belongs to Country and State. Country has many users and has many States. States belong to Country.

I would like to only select States for a particular Country. I want to match the country_id from the User model to the country_id from the State model. I thought about using State.where('something;).order('name'). However I do not know how I would code the SQL for this. I am using a PostgreSQL database. The examples I have found were for other databases.

The second question relates to how the list looks. I would like to change the background color along with the font color to match the input fields on my website. I tried the following code but could not get it working.

'collection-select-class'})  %>

My CSS code is:

.collection-select-class {
  background-color: #333333;
  color: @yellow;
}

I also tried using the option tag but it did not change anything.

Any help would be appreciated.

Problem courtesy of: Pamela Cook - LightBe Corp

Solution

CSS does not currently support that feature.

Look here:

HTML

Solution courtesy of: eoghanm

Discussion

View additional discussion.



This post first appeared on CSS3 Recipes - The Solution To All Your Style Problems, please read the originial post: here

Share the post

Selecting Records Using collection_select and Using CSS for Formatting

×

Subscribe to Css3 Recipes - The Solution To All Your Style Problems

Get updates delivered right to your inbox!

Thank you for your subscription

×