Class: Spree::Admin::UsersController
Instance Method Summary
collapse
#bulk_add_tags, #bulk_remove_tags
belongs_to, #destroy, #edit, #index, #new, #update
#apply_table_sort, #custom_sort_active?, #process_table_query_state, #table, #table_key, #table_registered?
#add_breadcrumb_icon_instance_var
Instance Method Details
#create ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'app/controllers/spree/admin/users_controller.rb', line 52
def create
@user = Spree.user_class.new(user_params)
@user.password ||= SecureRandom.hex(16) @user.password_confirmation ||= @user.password
if @user.save
flash[:success] = flash_message_for(@user, :successfully_created)
redirect_to spree.admin_user_path(@user)
else
render :new, status: :unprocessable_content
end
end
|
#location_after_save ⇒ Object
79
80
81
|
# File 'app/controllers/spree/admin/users_controller.rb', line 79
def location_after_save
spree.admin_user_path(@user)
end
|
#model_class ⇒ Object
65
66
67
|
# File 'app/controllers/spree/admin/users_controller.rb', line 65
def model_class
Spree.user_class
end
|
#search ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'app/controllers/spree/admin/users_controller.rb', line 24
def search
query = params[:q]&.strip
head :ok and return if query.blank? || query.length < 3
scope = model_class.accessible_by(current_ability, :index)
scope = scope.where.not(id: params[:omit_ids].split(',')) if params[:omit_ids].present?
@users = scope.includes(:bill_address, :ship_address, avatar_attachment: :blob)
.search(query)
.limit(params[:limit] || 10)
respond_to do |format|
format.turbo_stream do
render turbo_stream: [
turbo_stream.replace(
'users_search_results',
partial: 'spree/admin/users/search_results',
locals: { users: @users }
)
]
end
end
end
|
#select_options ⇒ Object
16
17
18
19
20
21
22
|
# File 'app/controllers/spree/admin/users_controller.rb', line 16
def select_options
q = params[:q]
ransack_params = q.is_a?(String) ? { email_cont: q } : q
users = model_class.accessible_by(current_ability).ransack(ransack_params).result.order(:email).limit(50)
render json: users.pluck(:id, :email).map { |id, email| { id: id, name: email } }
end
|
#set_current_store ⇒ Object
Skip setting current store for users as they don’t need store assignment and the stores association goes through role_users which requires a role
75
76
77
|
# File 'app/controllers/spree/admin/users_controller.rb', line 75
def set_current_store
end
|
#show ⇒ Object
48
49
50
|
# File 'app/controllers/spree/admin/users_controller.rb', line 48
def show
add_breadcrumb @user.name, spree.admin_user_path(@user)
end
|
#update_turbo_stream_enabled? ⇒ Boolean
69
70
71
|
# File 'app/controllers/spree/admin/users_controller.rb', line 69
def update_turbo_stream_enabled?
true
end
|