You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.1 KiB
49 lines
1.1 KiB
class TrustieHacksController < ApplicationController
|
|
before_action :require_admin, :except => [:index]
|
|
before_action :require_login, :except => [:index]
|
|
before_action :find_hackathon
|
|
before_action :find_hack, :except => [:create, :index]
|
|
|
|
def index
|
|
## 分页参数
|
|
page = params[:page] || 1
|
|
limit = params[:limit] || 16
|
|
|
|
hacks = @hackathon.trustie_hacks
|
|
@hackathon_users_count = hacks.sum(:hack_users_count)
|
|
|
|
@hacks = hacks.page(page).per(limit)
|
|
|
|
end
|
|
|
|
def edit ;end
|
|
|
|
def create
|
|
@hackathon.trustie_hacks.create!(name: params[:name], description: params[:description])
|
|
render_ok
|
|
end
|
|
|
|
def update
|
|
@hack.update_attributes(name: params[:name], description: params[:description])
|
|
end
|
|
|
|
def edit_hackathon ;end
|
|
|
|
def update_hackathon
|
|
@hackathon.update_attributes(name: params[:name], description: params[:description])
|
|
end
|
|
|
|
|
|
private
|
|
|
|
def find_hackathon
|
|
@hackathon = TrustieHackathon.first ||
|
|
TrustieHackathon.create(name: params[:name], description: params[:description])
|
|
end
|
|
|
|
def find_hack
|
|
@hack = TrustieHack.find params[:id]
|
|
end
|
|
|
|
end
|