Class: Apidae::SelectionsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/apidae/selections_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#apidae_user, #check_user_data!, #user_has_data?, #user_is_admin?

Instance Method Details

#createObject



26
27
28
29
30
31
32
33
34
# File 'app/controllers/apidae/selections_controller.rb', line 26

def create
  @selection = Selection.new(selection_params)

  if @selection.save
    redirect_to @selection, notice: 'Selection was successfully created.'
  else
    render :new
  end
end

#destroyObject



44
45
46
47
# File 'app/controllers/apidae/selections_controller.rb', line 44

def destroy
  @selection.destroy
  redirect_to selections_url, notice: 'Selection was successfully destroyed.'
end

#editObject



23
24
# File 'app/controllers/apidae/selections_controller.rb', line 23

def edit
end

#indexObject



7
8
9
10
11
12
13
14
# File 'app/controllers/apidae/selections_controller.rb', line 7

def index
  if user_is_admin?
    @selections = Selection.all
  else
    projects_ids = Project.where(apidae_id: apidae_user.apidae_projects_ids).map {|p| p.id}
    @selections = Selection.where(apidae_project_id: projects_ids)
  end
end

#newObject



19
20
21
# File 'app/controllers/apidae/selections_controller.rb', line 19

def new
  @selection = Selection.new
end

#refreshObject



49
50
51
52
53
54
55
56
# File 'app/controllers/apidae/selections_controller.rb', line 49

def refresh
  referrer = (session.delete(:referrer) || selections_url)
  if @selection && @selection.add_or_refresh_objs
    redirect_to referrer, notice: "La sélection a bien été mise à jour."
  else
    redirect_to referrer, alert: "Une erreur s'est produite lors de la mise à jour de la sélection."
  end
end

#showObject



16
17
# File 'app/controllers/apidae/selections_controller.rb', line 16

def show
end

#updateObject



36
37
38
39
40
41
42
# File 'app/controllers/apidae/selections_controller.rb', line 36

def update
  if @selection.update(selection_params)
    redirect_to @selection, notice: 'Selection was successfully updated.'
  else
    render :edit
  end
end