Skip to content

Instantly share code, notes, and snippets.

@rorens05
Created July 19, 2025 17:39
Show Gist options
  • Save rorens05/15a736c73e6280c2af503dd4f22b5fe5 to your computer and use it in GitHub Desktop.
Save rorens05/15a736c73e6280c2af503dd4f22b5fe5 to your computer and use it in GitHub Desktop.
Select 2 Stimulus Controller
def provinces
data = Province
.ransack(name_cont: params[:q], region_id_eq: params[:region_id])
.result
.limit(20)
render json: data.map { |item| { id: item.id, text: item.name } }
end
f.input :province,
as: :select,
input_html: {
data: {
controller: 'select2',
url: provinces_select_address_index_path,
'dependent-input-id': 'job_seeker_personal_information_region_id',
'dependent-param-name': 'region_id'
}
},
collection: f.object.province.present? ? [f.object.province] : []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment