a

Ruby code posted by a
created at 08 Jan 04:32, updated at 14 Jan 04:02

Edit | Back
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
class Admin::UsersController < Admin::ApplicationController
  before_action :set_user, only: [:show, :edit, :update, :destroy]
  respond_to :html

  def index
    @admin_users = User.page(params[:page]).per(10)

    respond_with(@admin_users)
  end

  def show
    respond_with(@admin_user, :layout => !request.xhr?)
  end

  def new
    @admin_user = User.new
    respond_with(@admin_user)
  end

  def edit
  end

  def set_agent
  end

  def create
    @admin_user = User.new(user_params)
    @admin_user.save

    redirect_to :action => :index, notice: "成功#{I18n.t(action_name)}#{I18n.t('admin/' + controller_name)}"
  end

  def update
    @admin_user.update_without_password(user_params)

    redirect_to :action => :index, notice: "成功#{I18n.t(action_name)}#{I18n.t('admin/' + controller_name)}"
  end

  def destroy
    @admin_user.destroy
    
    redirect_to :action => :index, notice: "成功#{I18n.t(action_name)}#{I18n.t('admin/' + controller_name)}"
  end

  private
    def set_user
      @admin_user = User.find(params[:id])
    end
    def user_params
      params.require(:user).permit(:phone, :name, :email, :gender, :role_id, :avatar, :seal)
    end
end
1.2 KB in 3 ms with coderay