diff --git a/app/controllers/trainings_controller.rb b/app/controllers/trainings_controller.rb index cfab83cb..e3a429b7 100644 --- a/app/controllers/trainings_controller.rb +++ b/app/controllers/trainings_controller.rb @@ -8,6 +8,9 @@ class TrainingsController < ApplicationController # ROOT_URL = ENV["wechat_url"] || "#{Setting.protocol}://#{Setting.host_name}" # # before_filter :authenticate, except: [:auth, :auth_callback, :pay_callback] + # + before_filter :find_tag_id + before_filter :find_training, only: [:show, :test] before_filter :valid_training, only: [:pay, :result, :pay_js] @@ -15,18 +18,18 @@ class TrainingsController < ApplicationController layout 'base_trainings' - TAG_ID = 'bigdata_hnjcxy_2019' + # TAG_ID = 'bigdata_hnjcxy_2019' def show @training = current_training url = nil if @training && !@training.pay? - url = enroll_training_path(id: TAG_ID) + url = enroll_training_path(id: @tag_id) elsif @training && @training.pay? - url = result_training_path(id: TAG_ID) + url = result_training_path(id: @tag_id) else - url = enroll_training_path(id: TAG_ID) + url = enroll_training_path(id: @tag_id) end redirect_to url @@ -45,7 +48,7 @@ class TrainingsController < ApplicationController # 防止重复支付,对于已支付过的,不应该再到这个页来 if @training.payed? - redirect_to result_training_path(id: TAG_ID) + redirect_to result_training_path(id: @tag_id) return end @@ -100,11 +103,15 @@ class TrainingsController < ApplicationController def create @training = current_training || Training.new(params) - @training.training_type = Training::Training_Type + @training.training_type = @training_type + if @training_type == 3 + @training.research_field = params[:research_field].reject(&:blank?).uniq.join(",") + end @training.openid = session[:wechat_open_id] @training.save! - redirect_to pay_training_path(id: TAG_ID) + redirect_to enroll_training_path(id: @tag_id) + # redirect_to pay_training_path(id: @tag_id) end @@ -116,7 +123,7 @@ class TrainingsController < ApplicationController end @training.update_attributes(params) - redirect_to pay_training_path(id: TAG_ID) + redirect_to pay_training_path(id: @tag_id) end @@ -168,7 +175,7 @@ class TrainingsController < ApplicationController if params[:js] == 'true' _pay_js(training_info.fee) else - redirect_to url = result_training_path(id: TAG_ID) + redirect_to url = result_training_path(id: @tag_id) end end @@ -232,11 +239,11 @@ class TrainingsController < ApplicationController url = '' if !@training - url = training_path(id: TAG_ID) + url = training_path(id: @tag_id) elsif !@training.pay? - url = enroll_training_path(id: TAG_ID) + url = enroll_training_path(id: @tag_id) else - url = result_training_path(id: TAG_ID) + url = result_training_path(id: @tag_id) end redirect_to url @@ -262,8 +269,14 @@ class TrainingsController < ApplicationController end end + def find_tag_id + @tag_id = params[:id] + @training_type = @tag_id == "aeee0601_2019" ? 3 : @tag_id == "ceeaa06_2019" ? 4 : 0 + render_404 if @training_type == 0 + end + def find_training - if params[:id] == TAG_ID + if params[:id] == @tag_id @training = current_training else render_404 @@ -271,12 +284,12 @@ class TrainingsController < ApplicationController end def current_training - Training.where(openid: session[:wechat_open_id], training_type: Training::Training_Type).first + Training.where(openid: session[:wechat_open_id], training_type: @training_type).first end def valid_training unless current_training - redirect_to training_path(id: TAG_ID) + redirect_to training_path(id: @tag_id) end end diff --git a/app/models/training.rb b/app/models/training.rb index 4c1f182e..a5794de2 100644 --- a/app/models/training.rb +++ b/app/models/training.rb @@ -3,7 +3,7 @@ class Training < ActiveRecord::Base attr_accessible :address, :email, :name, :phone, :position, :school, :sex, :openid, :training_type, :major, :student_id - # training_type 1 2018-培训会 2 警察学院大数据培训会 + # training_type 1 2018-培训会 2 警察学院大数据培训会 3 大数据和人工智能 4 工程教育认证 has_one :training_payinfo diff --git a/app/views/trainings/enroll.html.erb b/app/views/trainings/enroll.html.erb index fc9e7234..149de110 100644 --- a/app/views/trainings/enroll.html.erb +++ b/app/views/trainings/enroll.html.erb @@ -1,19 +1,19 @@ <% if false %> -
湖南警察学院大数据培训缴费
- <%= form_for @training do |f| %> -基本信息
-湖南警察学院大数据培训缴费
+ <%= form_for @training do |f| %> +基本信息
+信息技术新工科产学研联盟师资培训班
<%= form_for @training do |f| %> -基本信息
-基本信息
+您的授课/研究领域(最少选1项)
通讯地址
-通讯地址
+