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

你应该声明@events销毁动作

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 回答