Ask A Question

Notifications

You’re not receiving notifications from this thread.

dymanic data filter with jquery

JM 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

Reply
Join the discussion
Create an account Log in

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

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

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