From 405b362470bf2daf4c9e653feb5da015684e78e5 Mon Sep 17 00:00:00 2001 From: huang Date: Wed, 7 Feb 2018 16:01:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=AD=90=E7=B1=BB=E5=88=AB?= =?UTF-8?q?=E4=B8=8E=E6=95=B0=E6=8D=AE=E4=B8=BB=E7=B1=BB=E5=88=AB=E7=9A=84?= =?UTF-8?q?=E4=B8=80=E4=BA=9B=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/statistics_controller.rb | 13 ++++++ app/views/statistics/_form.html.erb | 42 +++++++++++-------- app/views/statistics/index.html.erb | 23 +++------- config/routes.rb | 6 ++- ...180207065530_add_catogory_to_statistics.rb | 6 +++ db/schema.rb | 10 +++-- 6 files changed, 60 insertions(+), 40 deletions(-) create mode 100644 db/migrate/20180207065530_add_catogory_to_statistics.rb diff --git a/app/controllers/statistics_controller.rb b/app/controllers/statistics_controller.rb index b7fd0b8c0..00cca9816 100644 --- a/app/controllers/statistics_controller.rb +++ b/app/controllers/statistics_controller.rb @@ -2,6 +2,7 @@ class StatisticsController < ApplicationController # GET /statistics # GET /statistics.json layout 'base_statistic' + before_filter :get_date, :only => [:index, :new, :edit] def index @statistics = Statistic.all @@ -82,4 +83,16 @@ class StatisticsController < ApplicationController format.json { head :no_content } end end + + def get_sub_category + respond_to do |format| + format.js + end + end + + private + def get_date + @main_categories = MainCategory.all + @sub_categories = params[:main_category_id].present? ? SubCategory.where(:main_category_id => params[:main_category_id]) : SubCategory.all + end end diff --git a/app/views/statistics/_form.html.erb b/app/views/statistics/_form.html.erb index 8b65ed2bc..4106aa5a2 100644 --- a/app/views/statistics/_form.html.erb +++ b/app/views/statistics/_form.html.erb @@ -18,25 +18,22 @@
+ <%= f.select :main_category_id, (@main_categories.collect { |mc| [mc.name, mc.id] }), + {:no_label => true}, :onchange => "get_sub_category(this.options[this.options.selectedIndex].value)", + :class => "w150" %> <%#= f.text_field :description %> -
- -
    -
  • 开发数据1
  • -
  • 开发数据2
  • -
  • 开发数据3
  • -
  • 开发数据4
  • -
-
-
- -
    -
  • 开发数据1
  • -
  • 开发数据2
  • -
  • 开发数据3
  • -
  • 开发数据4
  • -
-
+ + + + + + + + + + + +
@@ -70,6 +67,15 @@