Skip to content

Instantly share code, notes, and snippets.

@kivanio
Forked from Dglgmut/city_neighbourhood.rb
Last active August 29, 2015 14:16
Show Gist options
  • Save kivanio/9400aa50c749e7e52593 to your computer and use it in GitHub Desktop.
Save kivanio/9400aa50c749e7e52593 to your computer and use it in GitHub Desktop.
ActiveAdmin.register CityNeighbourhood do
member_action :change_neighbourhoods, :method => :get do
@neighbourhoods = City.find_by_id(params[:city_id]).try(:neighbourhoods)
render :text => view_context.options_from_collection_for_select(@neighbourhoods, :id, :name)
end
#...
form do |f|
f.input :city, input_html: {
onchange: remote_get("change_neighbourhoods", 'city_id', :neighbourhood_id)
}
f.input :neighbourhood
end
#...
end
module ActiveAdmin::ViewsHelper
def remote_get(path, member,target_tag_id)
"$.get('#{path}/?#{member}=' + $('##{member}').val(),
function(data) {$('##{target_tag_id}').html(data);}
);"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment