I have a country attribute to my guidelines model. I don\'t want to use a plugin, I just want to have country as a string. Everything is working until I try to edit a guide
Use country_select. Seems to work fine with Rails 4.1 if you're doing this recently. Plus Rails old repo links to this one rather than country-select.
First you need to add the gem in GemFile
gem 'country-select'
Create a helper file '/app/helpers/active_admin/views_helper.rb'. Add the below code
module ActiveAdmin::ViewsHelper
def country_dropdown
ActionView::Helpers::FormOptionsHelper::COUNTRIES
end
end
In your view file use
form do |f|
f.inputs do
f.input :country, as: :select, collection: country_dropdown
end
f.actions
end
I guess you could install the gem, and then override the display in active_admin.
I recommend you to use the country-select
:
gem 'country-select'
I spent a lot of hours to find out why country-select is not working in my form :)
You're using ActiveAdmin, so you're also using Formtastic.
In Formtastic, in the file formtastic/lib/formtastic/inputs/country_input.rb it clearly says:
# Rails doesn't come with a `country_select` helper by default any more, so you'll need to do
# one of the following:
#
# * install the [country_select](https://github.com/stefanpenner/country_select) gem
# * install any other country_select plugin that behaves in a similar way
# * roll your own `country_select` helper with the same args and options as the Rails one
I would add gem 'country-select'
to your Gemfile and do a bundle install as is the simplest and fastest solution.
I'm not sure where you get this form code from but I had the same issue with Active Admin and resolved it by explicitly instructing the form to treat the field as a string:
ActiveAdmin.register Guideline do
form do |f|
f.inputs 'Details' do
f.input :country, :as => :string
end
f.actions
end
end