1
在管理結束時,我認爲「用戶」表,我想它的被下令:ID在管理我的排序表的順序 - 軌道
我可以在這個手動每次我去做到那個管理屏幕,但有沒有辦法默認顯示按ID排序的用戶表?
管理/ users_controller.rb:
class Admin::UsersController < ApplicationController
before_action :set_user, only: [:show, :edit, :update, :destroy]
before_action :authenticate_admin
layout 'admin_application'
def index
@search = User.search(params[:q])
@users = @search.result
end
,並在管理/用戶/ index.html.haml
%table.users_table
%thead
%tr
%th= sort_link(@search, :id, 'ID')
%th= sort_link(@search, :name, 'Name')
%th= sort_link(@search, :username, 'Username')
%th Email
%th City
%th Review count
%th Last logged in time
%th
%th
%th
%tbody
- @users.each do |user|
%tr
%td= user.id
%td= user.name
%td= user.username
%td= user.email
%td= user.city
%td= user.reviews.count
- if user.has_logged_in?
%td= user.last_login.to_s(:long)
- else
%td No login yet
%td= link_to 'Show', admin_user_path(user)
%td= link_to 'Edit', edit_admin_user_path(user)
%td= link_to 'Destroy', admin_user_path(user), :method => :delete, :data => { :confirm => 'Are you sure?' }
完美,謝謝! – tessad
請投票:) –