Skip to content

Instantly share code, notes, and snippets.

@Dglgmut
Last active December 13, 2019 15:20
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save Dglgmut/6328501 to your computer and use it in GitHub Desktop.
Save Dglgmut/6328501 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