[Solved] Ruby on Rails UJS


It looks to me like the relevant code to the question is this:

#dynamicLoadingPanel
  = render 'schedules/named_players'

And that somewhere (not in code shown), and update is posted to Availabilities#create, and what is returned is a fresh version of schedules/named_players and dynamically insert that into the page within #dynamicLoadingPanel.

Here’s my take:

# _schedules/available_players.html.haml
#dynamicLoadingPanel
  AVAILABILTY IS UNKNOWN

Choose availability:
#availabilities
  = link_to 'available', '#', :data => 'available'
  = link_to 'busy',      '#', :data => 'busy'

:javascript
  $(function(){
    $('#availabilities a').click(function(){
      $('#dynamicLoadingPanel').load(
        "/availabilities",
        { availability: $(this).attr('data') }
      );
    });
  });

# availabilities/create.html.haml
I will be:
= params[:availability]

When you click one of the availabilities links, it creates a UJS call to post to availabilites#create (the extra parameters are required to make it a post, without them, load() will perform a get.

When availabilities#create is done, it renders create.html.haml, which renders whatever is in the view (this is the place to put = render :partial => 'schedules/named_players' in your own code).

The jquery method .load() replaces the innerHTML of the selector with what is returned from your post.

solved Ruby on Rails UJS