All threads / dymanic data filter with jquery

Ask A Question

Notifications

You’re not receiving notifications from this thread.

dymanic data filter with jquery

John Munyi asked in Javascript

Hi Chris I want to replace the create action of my app with dynamic jQuery data pulling so that user has a chance to see the data pulled from the DB before the actual create happens , so currently my create action is then one doing all the dirty work but incase a user abort before updating then a dirty record is saved here it is

  def create
     @attendance_sheet = AttendanceSheet.new(attendance_sheet_params)
     @team = Team.find(attendance_sheet_params[:team_id])
     @team.users.each do |u|
          @attendance_sheet.attendances.build(user: u)
    end

     respond_to do |format|
       if @attendance_sheet.save
        format.html { render :edit }
         format.json { render :show, status: :created, location: @attendance_sheet }
       else
         format.html { render :new }
         format.json { render json: @attendance_sheet.errors, status: :unprocessable_entity }
       end
    end
   end

NB: I am rendering edit to give the user to update the pulled record of user accordingly ..... the attendances records added here are via nested attributes (not sure if it necessary to have that actually)

Now I am some jQuery in the line of :

 $(document).on 'ready page:load', ->
   $('.attendance').hide()
   list = $('.attendance').html() //this is the div to didplay users list from selected team
   $('#attendance_sheet_team_id').change ->

      team = $('#attendance_sheet_team_id :selected').text()

    //here now i wanna match the selected team with it users and show the hidden div with all the users from that team in it , this is the bit where i am stuck .. on how to grab the nested from and query as well 

cheers

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 37,344+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.