Class: RatingsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#dev_only, #require_login

Methods included from SessionsHelper

#console?, #current_user, #debug?, #forget, #log_in, #log_out, #logged_in?, #remember, #toggle_console, #toggle_debug

Instance Method Details

#createObject



11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/ratings_controller.rb', line 11

def create
  @rating = Rating.create(ratings_params)

  if @rating.save
    flash[:success] = 'Successfully left rating!'
    redirect_to root_path
  else
    flash[:danger] = 'Failed to leave rating :('
    redirect_to root_path
  end
end

#editObject



23
24
25
26
27
# File 'app/controllers/ratings_controller.rb', line 23

def edit
  @rating = Rating.find(params[:id])
  @average = MetricsService.new(@rating.meal).meals_average
  render layout: false
end

#indexObject



2
3
4
# File 'app/controllers/ratings_controller.rb', line 2

def index
  @ratings = Rating.where(meal_id: params[:meal_id])
end

#newObject



6
7
8
9
# File 'app/controllers/ratings_controller.rb', line 6

def new
  @rating = Rating.new
  render layout: false
end

#updateObject



29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/ratings_controller.rb', line 29

def update
  @rating = Rating.find(params[:id])

  if @rating.update(ratings_params)
    flash[:success] = 'Successfully updated rating!'
    redirect_to root_path
  else
    flash[:danger] = 'Failed to update rating :('
    redirect_to root_path
  end
end