Ruby on rails 4 将视图返回到我在Rails视图中删除用户时开始的页面

Ruby on rails 4 将视图返回到我在Rails视图中删除用户时开始的页面,ruby-on-rails-4,will-paginate,Ruby On Rails 4,Will Paginate,环境: 操作系统:Windows 8.1 Ruby:2.1.5 铁路:4.2 在我的视图/users/index.html.erb中,我有: <h1>Listing Users</h1> <span class="eastdev_pagination"> <%= will_paginate @users, :container => false %> </span> <table class="table table-

环境: 操作系统:Windows 8.1 Ruby:2.1.5 铁路:4.2

在我的视图/users/index.html.erb中,我有:

<h1>Listing Users</h1>

<span class="eastdev_pagination">

<%= will_paginate @users, :container => false %>
</span>

<table class="table table-striped">
  <thead>
  <tr>
    <th>First</th>
    <th>Last</th>
    <th>Work phone</th>
    <th>City</th>
    <th>Organization</th>
    <th colspan="3"></th>
  </tr>
  </thead>

  <tbody>
  <% @users.each do |u| %>
    <tr>
      <td><%= u.first %></td>
      <td><%= u.last %></td>
      <% if u.work_phone %>
        <% phone = number_to_phone(u.work_phone, area_code: true) %>
        <td><%= phone %></td>
      <% else %>
        <td></td>
      <% end %>
      <td><%= u.city %></td>
      <td><%= u.organization %></td>
      <%= render partial: "layouts/show_edit_del_buttons", locals: {my_model: u} %>
    </tr>
  <% end %>
  </tbody>
</table>
<span class="eastdev_pagination">
  <%= will_paginate @users, :container => false %>
</span>

<br>
<td>
  <%= link_to my_model, class: 'btn btn-info', title: 'View', 'data-toggle' => 'tooltip', 'data-placement' => 'right' do %>
    <span class="glyphicon glyphicon-search"></span>
  <% end %>
<td>
<% if staff_access_level? %>
  <td>
    <%= link_to [:edit, my_model], class: 'btn btn-warning', title: 'Edit', 'data-toggle' => 'tooltip', 'data-placement' => 'right' do %>
      <span class="glyphicon glyphicon-pencil"></span>
    <% end %>
  </td>
  <td>
    <%= link_to my_model, method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger', title: 'Delete', 'data-toggle' => 'tooltip', 'data-placement' => 'right'  do %>
      <span class="glyphicon glyphicon-remove"></span>
    <% end %>
  </td>
<% end %>   
我遇到的问题是,当我删除一个用户时,我会返回到第一页。例如,我在分页的第5页,我在这里删除了一个用户,然后返回到第一个导航页

如何让视图返回到删除之前的页面

笔记: 如果我尝试以下方法:

<%= link_to my_model(:page => params[:page]), method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger', title: 'Delete', 'data-toggle' => 'tooltip', 'data-placement' => 'right'  do %>
    <span class="glyphicon glyphicon-remove"></span>
<% end %>>

在您所在的页面上删除后,您应该重定向用户。 看看你的销毁方法

def destroy
   @user.destroy
   respond_to do |format|
      format.html { redirect_to params[:page] ? users_url(page: params[:page]) : users_url }
      format.json { head :no_content }
   end
end 
将\u重定向到用户\u url

在这里,您应该在重定向时定义一个页面。 像这样

my_model=您的路径,如user_pathuser,page:params[:page]


我收到一条错误消息:未定义的方法“my_model”是的,这可能会起作用,但这并不能回答我的问题。你应该重读这个问题。好的,那么你如何解决你的问题呢。你能发布你的代码吗?但是你尝试了我的代码,应该可以解决你的问题。我读了你的问题,伙计…我的代码已经全部发布了。我有一个部分,我想用多个模型。它一直工作到我必须传递一个页面参数的时候,这时它就停止工作了。指定模型用户等意味着我需要6个部分,每个模型一个,而不是一个部分。
Method not found: my_model      
<%= link_to user_path(user, page: params[:page]), method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger', title: 'Delete', 'data-toggle' => 'tooltip', 'data-placement' => 'right'  do %>
  <span class="glyphicon glyphicon-remove"></span>
<% end %>
def destroy
   @user.destroy
   respond_to do |format|
      format.html { redirect_to params[:page] ? users_url(page: params[:page]) : users_url }
      format.json { head :no_content }
   end
end