From 7022b35da03e94c49d8c047e4237dda69a967739 Mon Sep 17 00:00:00 2001
From: daiao <358551898@qq.com>
Date: Wed, 6 Nov 2019 13:56:36 +0800
Subject: [PATCH] =?UTF-8?q?=E9=BB=91=E5=AE=A2=E6=9D=BE=E8=B0=83=E8=AF=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 app/controllers/trustie_hacks_controller.rb           | 11 +++++++----
 ...4825_add_trustie_hackathon_id_for_trustie_hacks.rb |  6 ++++++
 2 files changed, 13 insertions(+), 4 deletions(-)
 create mode 100644 db/migrate/20191106034825_add_trustie_hackathon_id_for_trustie_hacks.rb

diff --git a/app/controllers/trustie_hacks_controller.rb b/app/controllers/trustie_hacks_controller.rb
index f427caf72..d66f5a215 100644
--- a/app/controllers/trustie_hacks_controller.rb
+++ b/app/controllers/trustie_hacks_controller.rb
@@ -2,7 +2,7 @@ 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]
+  before_action :find_hack, :except => [:create, :index, :edit_hackathon, :update_hackathon]
 
   def index
     ## 分页参数
@@ -16,7 +16,7 @@ class TrustieHacksController < ApplicationController
 
   end
 
-  def edit ;end
+  def edit;end
 
   def create
     @hackathon.trustie_hacks.create!(name: params[:name], description: params[:description])
@@ -25,12 +25,15 @@ class TrustieHacksController < ApplicationController
 
   def update
     @hack.update_attributes(name: params[:name], description: params[:description])
+    render_ok
   end
 
-  def edit_hackathon ;end
+  def edit_hackathon
+  end
 
   def update_hackathon
     @hackathon.update_attributes(name: params[:name], description: params[:description])
+    render_ok
   end
 
 
@@ -38,7 +41,7 @@ class TrustieHacksController < ApplicationController
 
   def find_hackathon
     @hackathon = TrustieHackathon.first ||
-        TrustieHackathon.create(name: params[:name], description: params[:description])
+        TrustieHackathon.create!(name: params[:name], description: params[:description])
   end
 
   def find_hack
diff --git a/db/migrate/20191106034825_add_trustie_hackathon_id_for_trustie_hacks.rb b/db/migrate/20191106034825_add_trustie_hackathon_id_for_trustie_hacks.rb
new file mode 100644
index 000000000..0c2619ec7
--- /dev/null
+++ b/db/migrate/20191106034825_add_trustie_hackathon_id_for_trustie_hacks.rb
@@ -0,0 +1,6 @@
+class AddTrustieHackathonIdForTrustieHacks < ActiveRecord::Migration[5.2]
+  def change
+    add_column :trustie_hacks, :trustie_hackathon_id, :integer
+    add_index :trustie_hacks, :trustie_hackathon_id
+  end
+end