mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-07 21:48:16 -08:00
adding slugs to schools and categories
This commit is contained in:
parent
683fc31c5d
commit
1db61cd3e5
13 changed files with 42 additions and 12 deletions
|
|
@ -68,12 +68,12 @@ class CategoriesController < ApplicationController
|
||||||
private
|
private
|
||||||
def set_school
|
def set_school
|
||||||
redirect_to root_path and return false unless params.include?(:school_id)
|
redirect_to root_path and return false unless params.include?(:school_id)
|
||||||
@school = School.find(params[:school_id])
|
@school = School.friendly.find(params[:school_id])
|
||||||
redirect_to root_path and return false if @school.nil?
|
redirect_to root_path and return false if @school.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_category
|
def set_category
|
||||||
@category = Category.find(params[:id])
|
@category = Category.friendly.find(params[:id])
|
||||||
end
|
end
|
||||||
|
|
||||||
# Never trust parameters from the scary internet, only allow the white list through.
|
# Never trust parameters from the scary internet, only allow the white list through.
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ class QuestionsController < ApplicationController
|
||||||
private
|
private
|
||||||
def set_school
|
def set_school
|
||||||
redirect_to root_path and return false unless params.include?(:school_id)
|
redirect_to root_path and return false unless params.include?(:school_id)
|
||||||
@school = School.find(params[:school_id])
|
@school = School.friendly.find(params[:school_id])
|
||||||
redirect_to root_path and return false if @school.nil?
|
redirect_to root_path and return false if @school.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ class RecipientListsController < ApplicationController
|
||||||
private
|
private
|
||||||
# Use callbacks to share common setup or constraints between actions.
|
# Use callbacks to share common setup or constraints between actions.
|
||||||
def set_school
|
def set_school
|
||||||
@school = School.find(params[:school_id])
|
@school = School.friendly.find(params[:school_id])
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_recipient_list
|
def set_recipient_list
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ class RecipientsController < ApplicationController
|
||||||
private
|
private
|
||||||
# Use callbacks to share common setup or constraints between actions.
|
# Use callbacks to share common setup or constraints between actions.
|
||||||
def set_school
|
def set_school
|
||||||
@school = School.find(params[:school_id])
|
@school = School.friendly.find(params[:school_id])
|
||||||
end
|
end
|
||||||
|
|
||||||
# Use callbacks to share common setup or constraints between actions.
|
# Use callbacks to share common setup or constraints between actions.
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ class SchedulesController < ApplicationController
|
||||||
private
|
private
|
||||||
# Use callbacks to share common setup or constraints between actions.
|
# Use callbacks to share common setup or constraints between actions.
|
||||||
def set_school
|
def set_school
|
||||||
@school = School.find(params[:school_id])
|
@school = School.friendly.find(params[:school_id])
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_schedule
|
def set_schedule
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ class SchoolsController < ApplicationController
|
||||||
private
|
private
|
||||||
# Use callbacks to share common setup or constraints between actions.
|
# Use callbacks to share common setup or constraints between actions.
|
||||||
def set_school
|
def set_school
|
||||||
@school = School.find(params[:id] || params[:school_id])
|
@school = School.friendly.find(params[:id] || params[:school_id])
|
||||||
end
|
end
|
||||||
|
|
||||||
# Never trust parameters from the scary internet, only allow the white list through.
|
# Never trust parameters from the scary internet, only allow the white list through.
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,9 @@ class Category < ApplicationRecord
|
||||||
|
|
||||||
scope :for_parent, -> (category=nil) { where(parent_category_id: category.try(:id)) }
|
scope :for_parent, -> (category=nil) { where(parent_category_id: category.try(:id)) }
|
||||||
|
|
||||||
|
include FriendlyId
|
||||||
|
friendly_id :name, :use => [:slugged]
|
||||||
|
|
||||||
def path
|
def path
|
||||||
p = self
|
p = self
|
||||||
items = [p]
|
items = [p]
|
||||||
|
|
|
||||||
|
|
@ -7,4 +7,7 @@ class School < ApplicationRecord
|
||||||
|
|
||||||
validates :name, presence: true
|
validates :name, presence: true
|
||||||
|
|
||||||
|
include FriendlyId
|
||||||
|
friendly_id :name, :use => [:slugged]
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
6
db/migrate/20170316194058_add_slug_to_school.rb
Normal file
6
db/migrate/20170316194058_add_slug_to_school.rb
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
class AddSlugToSchool < ActiveRecord::Migration[5.0]
|
||||||
|
def change
|
||||||
|
add_column :schools, :slug, :string
|
||||||
|
add_index :schools, :slug, unique: true
|
||||||
|
end
|
||||||
|
end
|
||||||
6
db/migrate/20170316194122_add_slug_to_category.rb
Normal file
6
db/migrate/20170316194122_add_slug_to_category.rb
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
class AddSlugToCategory < ActiveRecord::Migration[5.0]
|
||||||
|
def change
|
||||||
|
add_column :categories, :slug, :string
|
||||||
|
add_index :categories, :slug, unique: true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20170316154053) do
|
ActiveRecord::Schema.define(version: 20170316194122) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
|
@ -40,6 +40,8 @@ ActiveRecord::Schema.define(version: 20170316154053) do
|
||||||
t.integer "parent_category_id"
|
t.integer "parent_category_id"
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
|
t.string "slug"
|
||||||
|
t.index ["slug"], name: "index_categories_on_slug", unique: true, using: :btree
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "districts", force: :cascade do |t|
|
create_table "districts", force: :cascade do |t|
|
||||||
|
|
@ -141,6 +143,8 @@ ActiveRecord::Schema.define(version: 20170316154053) do
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
t.text "description"
|
t.text "description"
|
||||||
|
t.string "slug"
|
||||||
|
t.index ["slug"], name: "index_schools_on_slug", unique: true, using: :btree
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "users", force: :cascade do |t|
|
create_table "users", force: :cascade do |t|
|
||||||
|
|
|
||||||
|
|
@ -143,7 +143,8 @@ namespace :data do
|
||||||
bad_answers = {}
|
bad_answers = {}
|
||||||
year = '2016'
|
year = '2016'
|
||||||
['student_responses', 'teacher_responses'].each do |file|
|
['student_responses', 'teacher_responses'].each do |file|
|
||||||
target_group = Question.target_groups["for_#{file.split('_')[0]}s"]
|
recipients = file.split('_')[0]
|
||||||
|
target_group = Question.target_groups["for_#{recipients}s"]
|
||||||
csv_string = File.read(File.expand_path("../../../data/#{file}_#{year}.csv", __FILE__))
|
csv_string = File.read(File.expand_path("../../../data/#{file}_#{year}.csv", __FILE__))
|
||||||
csv = CSV.parse(csv_string, :headers => true)
|
csv = CSV.parse(csv_string, :headers => true)
|
||||||
csv.each do |row|
|
csv.each do |row|
|
||||||
|
|
@ -158,6 +159,11 @@ namespace :data do
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
|
recipient_list = school.recipient_lists.find_by_name("#{recipients.titleize} List")
|
||||||
|
if recipient_list.nil?
|
||||||
|
school.recipient_lists.create(name: "#{recipients.titleize} List")
|
||||||
|
end
|
||||||
|
|
||||||
respondent_id = row['RespondentID']
|
respondent_id = row['RespondentID']
|
||||||
recipient_id = respondent_map[respondent_id]
|
recipient_id = respondent_map[respondent_id]
|
||||||
if recipient_id.present?
|
if recipient_id.present?
|
||||||
|
|
@ -168,6 +174,8 @@ namespace :data do
|
||||||
)
|
)
|
||||||
respondent_map[respondent_id] = recipient.id
|
respondent_map[respondent_id] = recipient.id
|
||||||
end
|
end
|
||||||
|
recipient_list.recipient_id_array << recipient.id
|
||||||
|
recipient_list.save!
|
||||||
|
|
||||||
row.each do |key, value|
|
row.each do |key, value|
|
||||||
next if value.nil? or key.nil?
|
next if value.nil? or key.nil?
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ RSpec.describe "recipients/index", type: :view do
|
||||||
:home_language_id => 2,
|
:home_language_id => 2,
|
||||||
:income => "Income",
|
:income => "Income",
|
||||||
:opted_out => false,
|
:opted_out => false,
|
||||||
:school_id => @school.to_param
|
:school_id => @school.id
|
||||||
),
|
),
|
||||||
Recipient.create!(
|
Recipient.create!(
|
||||||
:name => "Name",
|
:name => "Name",
|
||||||
|
|
@ -27,7 +27,7 @@ RSpec.describe "recipients/index", type: :view do
|
||||||
:home_language_id => 2,
|
:home_language_id => 2,
|
||||||
:income => "Income",
|
:income => "Income",
|
||||||
:opted_out => false,
|
:opted_out => false,
|
||||||
:school_id => @school.to_param
|
:school_id => @school.id
|
||||||
)
|
)
|
||||||
])
|
])
|
||||||
end
|
end
|
||||||
|
|
@ -42,6 +42,6 @@ RSpec.describe "recipients/index", type: :view do
|
||||||
assert_select "tr>td", :text => 2.to_s, :count => 2
|
assert_select "tr>td", :text => 2.to_s, :count => 2
|
||||||
assert_select "tr>td", :text => "Income".to_s, :count => 2
|
assert_select "tr>td", :text => "Income".to_s, :count => 2
|
||||||
assert_select "tr>td", :text => false.to_s, :count => 2
|
assert_select "tr>td", :text => false.to_s, :count => 2
|
||||||
assert_select "tr>td", :text => @school.to_param, :count => 2
|
assert_select "tr>td", :text => @school.id.to_s, :count => 2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue