-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathspaces_controller.rb
More file actions
83 lines (72 loc) · 1.88 KB
/
Copy pathspaces_controller.rb
File metadata and controls
83 lines (72 loc) · 1.88 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# The controller for actions related to the Spaces model
class SpacesController < ApplicationController
before_action :ensure_feature_enabled
before_action :set_space, only: [:show, :edit, :update, :destroy]
before_action :set_breadcrumbs
# GET /spaces
def index
@spaces = Space.all
respond_to do |format|
format.html
end
end
# GET /spaces/1
def show
respond_to do |format|
format.html
end
end
# GET /spaces/new
def new
authorize Space
@space = Space.new
end
# GET /spaces/1/edit
def edit
authorize @space
end
# POST /spaces
def create
authorize Space
@space = Space.new(space_params)
@space.user = current_user
respond_to do |format|
if @space.save
@space.create_activity :create, owner: current_user
format.html { redirect_to @space, notice: 'Space was successfully created.' }
else
format.html { render :new }
end
end
end
# PATCH/PUT /spaces/1
def update
authorize @space
respond_to do |format|
if @space.update(space_params)
@space.create_activity(:update, owner: current_user) if @space.log_update_activity?
format.html { redirect_to @space, notice: 'Space was successfully updated.' }
else
format.html { render :edit }
end
end
end
# DELETE /spaces/1
def destroy
authorize @space
@space.create_activity :destroy, owner: current_user
@space.destroy
respond_to do |format|
format.html { redirect_to spaces_path, notice: 'Space was successfully deleted.' }
end
end
private
def set_space
@space = Space.find(params[:id])
end
def space_params
permitted = [:title, :description, :theme, :image, :image_url, { administrator_ids: [] }, { enabled_features: [] }]
permitted += [:host] if current_user.is_admin?
params.require(:space).permit(*permitted)
end
end