0

破壊が成功した後、イベントリストの部分を更新する方法を見てください

_event_list.haml (更新用の部分)

%table.twelve#events
  %thead
    %tr
      -#%th Game/Event
      -#%th Result
      -#%th Team
      %th Opponent
      -#%th Date
      -#%th Time
      %th Location
      - if can? :update, @event
        %th.span1 Manager
  %tbody
    - @events.each do |event|
      %tr
        -#%td= event_display(event.event)
        -#%td= find_result(event)
        -#%td= event.team.name
        %td= link_to event.opponent.name, event
        -#%td= check_date(event)
        -#%td
          = "#{event.datetime.to_s(:event_time)} - #{end_time(event)}"
          %div{:style => 'font-size: .8em;color:#666; margin-top: 3px'}= "Arrived at #{arrive_time(event)}"
        %td
          - if event.location
            = link_to event.location.name, event, :rel => 'tooltip-html', :title => 'View ' + event.location.name
        - if can? :update, @event
          %td
            .btn-group
              %button.btn.dropdown-toggle{"data-toggle" => "dropdown"}
                %i.icon-pencil
                Manage
                %span.caret
              %ul.dropdown-menu
                %li= link_to "Edit #{event_display(event.event)}", edit_event_path(event)
                %li= link_to "Delete #{event_display(event.event)}", event, :method => :delete, :remote => :true, :class => 'deleteRecord'

destroy.js.erb $("events").html("<%= escape_javascript(render(:partial => "events_list")) %>");

イベントコントローラー

def destroy
    @event = Event.find(params[:id])
    @event.destroy

    respond_to do |format|
      format.html { redirect_to(events_url,
                                :notice => "#{event_display_c(@event.event)} vs #{@event.opponent.name} was successfully deleted.") }
      format.js
    end
  end
4

1 に答える 1

3

@eventsdestroy アクションで宣言する必要があります

def destroy
  @event = Event.find(params[:id])
  @event.destroy

  respond_to do |format|
    format.html { redirect_to(events_url, notice: "#{event_display_c(@event.event)} vs #{@event.opponent.name} was successfully deleted.") }
    format.js { @events = Event.all # or something }
  end
end

次に変更destroy.js.erbします(jqueryを想定)

$("#events").replaceWith("<%= escape_javascript render('events_list') %>");
于 2013-02-05T13:45:32.793 に答える