populate dropdown

Hi, I am new for RoR i am using f.select for dropdown and want to populate it from database table i have a function in cities model which retrieve all cities and i am doing the follwoing to populate the dropdown f.select :city_id , @cities but it display a strange output with some # etc how i will do it and i dont want to use collection_select so thats mean how to write the function def self.find_all_cities    find(:all) end

thats how my function is how can i modify so that it gives me s refine array so that it did my business

Regards,

M I R wrote:

Hi, I am new for RoR i am using f.select for dropdown and want to populate it from database table i have a function in cities model which retrieve all cities and i am doing the follwoing to populate the dropdown f.select :city_id , @cities but it display a strange output with some # etc how i will do it and i dont want to use collection_select so thats mean how to write the function def self.find_all_cities    find(:all) end

thats how my function is how can i modify so that it gives me s refine array so that it did my business

Regards,

You can use this way

<%= collection_select(:city, :id, City.find_all_cities, :id, :city) %>

i have a working craigslist clone here:

download, install and play to learn more.

its ok for now, but when i go to edit page how will i populate the dropdown while the selected option will be the one coming from database suppose i have 3 cities ID City 1. London 2. Bristol 3. Cambridge when i was adding record i select Bristol with id 2 now when i go to edit page this one should be selected i was expecting some magic here {symfony apply this magic} but just the dropdown comes with first value selected, how i will handle it manualy and if there is some magic then please help me for either case

Regards,

M I R wrote:

i was expecting some magic here

The edit page should show the correct selection by "magic" if the form is correct. Could you show us the edit form that isnt working as expected?