ruby-on-rails-3inline-editingbest-in-place

How can i integrate country_select gem with best_in_place editing


I am using the best_in_place gem to edit records inline and country_select to render a list of countries to select from. When using best_in_place to edit a select field i do this:

<%= best_in_place(@home, :country_name, :type => :select, :collection => [[1, "Spain"], [2, "Italy"]]) %>

Now i like to get a list of all the countries that country_select has and pass that into the collection parameter. The country_select gem provides a simple helper to render the select field:

<%= country_select("home", "country_name") %>

I would like to replace the :collection parameter in best_in_place helper to include the list of countries provided by country_select. I know that best_in_place expects the [[key, value], [key, value],...] input into :collection, but i am not sure how to do this. Please advise. Thanks


Solution

  • Just do the following and it will work:

    <%= best_in_place @home, :country, type: :select, collection: (ActionView::Helpers::FormOptionsHelper::COUNTRIES.zip(ActionView::Helpers::FormOptionsHelper::COUNTRIES)) %>