Module: Ztree::Controller
- Extended by:
- ActiveSupport::Concern
- Included in:
- ActionController::Base
- Defined in:
- lib/ztree/controller.rb
Instance Method Summary collapse
Instance Method Details
#get_tree ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/ztree/controller.rb', line 4 def get_tree mo_str = params[:model_name] ztree_name = params[:ztree_name] || 'name' checked_ids = params[:checked_ids] || '' the_model = Object.const_get(mo_str) conditions = '' conditions += "name like '%#{params[:query]}%'" if params[:query] objs = the_model.where(conditions) opts = { name: ztree_name, checked_ids: checked_ids } render text: objs.to_ztree_node(opts).to_json end |
#sort_tree ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/ztree/controller.rb', line 19 def sort_tree return render text: 'error' unless params[:model_name] mo_str = params[:model_name] the_model = Object.const_get(mo_str) arr = params[:sorted_array] p_id = arr.shift parent = p_id != '0' ? the_model.find(p_id) : the_model parent.update_sorted_numbers(arr) render text: arr end |