خرید بک لینک

Vote count: 0

I'm trying to do a dynamic select, when user select school appear only the groups that belong to that school, but when I tried to change the select I got this error:

Missing partial admin/groups/_group with {:locale=>[:en], :formats=>[:js, :html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee]}.

CoffeeScript

$(document).on "page:change", ->
  $(document).on 'change', '#schools_select', (evt) ->
    $.ajax 'update_groups',
      type: 'GET'
      dataType: 'script'
      data: {
        school_id: $("#schools_select option:selected").val()
      }
      error: (jqXHR, textStatus, errorThrown) ->
        console.log("AJAX Error: #{errorThrown}")
      success: (data, textStatus, jqXHR) ->
        console.log("Dynamic school select OK!")

HTML

The school belongs to the model of the form, but the group isn't an attribute of the form.

    <div class="form-group">
      <%= f.label :school %><br>
      <%= f.select :school_id, options_for_select(@schools.active.collect { |school|
      [school.name.titleize, school.id] }, 1), {}, { id: 'schools_select' } %>
    </div>
    <div class="form-group">
      <%= label_tag :group %><br>
      <%= select_tag :group_id, options_for_select(@groups.active.collect { |group|
      [group.name.titleize, group.id] }, 1), { id: 'groups_select' } %>
    </div>

Javascript

$("#groups_select").empty().append("<%= escape_javascript(render(:partial => @groups)) %>")

Ruby

 def update_groups
   @groups = Group.where(school_id: params[:school_id])
   respond_to do |format|
     format.js
   end
 end

Routes

     get 'students/update_groups', as: 'update_groups'

asked 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: چهارشنبه 29 ارديبهشت 1395 ساعت: 7:05

صفحه بندی