dymanic data filter with jquery
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