-
Notifications
You must be signed in to change notification settings - Fork 105
Expand file tree
/
Copy pathtips_controller.rb
More file actions
56 lines (47 loc) · 1.71 KB
/
tips_controller.rb
File metadata and controls
56 lines (47 loc) · 1.71 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
# frozen_string_literal: true
class TipsController < ApplicationController
before_action { load_project }
before_action { load_user }
def index
if @project.present?
@tips = @project.tips.includes(:user).with_address
elsif @user.present?
if @user.bitcoin_address.present?
@tips = @user.tips.includes(:project)
else
flash[:error] = I18n.t('errors.user_not_found')
redirect_to users_path and return
end
else
@tips = Tip.with_address.includes(:project)
end
@tips = @tips.order(created_at: :desc)
.page(params[:page])
.per(params[:per_page] || 30)
respond_to do |format|
format.html
format.csv { render csv: @tips, except: %i[updated_at commit commit_message refunded_at decided_at], add_methods: %i[user_name project_name decided? claimed? paid? refunded? txid] }
end
end
private
def load_project
return unless pretty_project_path? || params[:project_id].present?
if pretty_project_path?
@project = Project.find_by_service_and_repo(params[:service], params[:repo])
elsif params[:project_id].present?
@project = Project.where(id: params[:project_id]).first
redirect_to project_tips_pretty_path(@project.host, @project.full_name) if @project
end
project_not_found unless @project
end
def load_user
return unless params[:user_id].present? || params[:nickname].present?
if params[:nickname].present?
@user = User.find_by_nickname(params[:nickname])
elsif params[:user_id].present?
@user = User.where(id: params[:user_id]).first
redirect_to user_tips_pretty_path(@user.nickname) if @user
end
user_not_found unless @user
end
end