Skip to content
Snippets Groups Projects
Commit 8a91291f authored by Mauricio Giacomini Girardello's avatar Mauricio Giacomini Girardello
Browse files

refactoring class methods for scopes concepts and add import topics task

parent f54da69e
No related branches found
No related tags found
No related merge requests found
......@@ -4,7 +4,6 @@ class LearningObjectsController < ApplicationController
include Reportable
before_action :authenticate_user!, except: [:index, :show]
before_action :set_learning_object, only: [:show, :edit, :update,
:destroy, :like, :bookmarks,
:collections, :upload, :upload_link, :download]
......@@ -21,7 +20,7 @@ class LearningObjectsController < ApplicationController
def new
@learning_object = LearningObject.new
@school_levels = ['Educação Infantil', 'Ensino Fundamental', 'Ensino Médio']
@subjects = Topic.all.map{|x| x.name}.uniq
@subjects = Topic.defaults
@types = LearningObject.default_types
@languages = Language.all
end
......
......@@ -10,10 +10,5 @@ class Topic < ActiveRecord::Base
validates_presence_of :name
validates_uniqueness_of :name
def self.default_list
['Artes', 'Biologia', 'Ciências', 'Educação Física', 'Filosofia',
'Física', 'Geografia', 'História', 'Matemática', 'Língua Portuguesa', 'Química', 'Sociologia'].map do |topic|
Topic.find_by_name(topic)
end
end
scope :defaults, -> { where(default: true) }
end
class CreateDefaultColumnForTopics < ActiveRecord::Migration
def change
add_column :topics, :default, :boolean, default: false
end
end
namespace :topics do
desc "Define defaults topics"
task :define_defaults => :environment do
['Artes', 'Biologia', 'Ciências', 'Educação Física', 'Filosofia',
'Física', 'Geografia', 'História', 'Matemática', 'Língua Portuguesa', 'Química', 'Sociologia'].map do |name|
t = Topic.find_by_name(name)
if t.class == Topic
t.default = true
t.save
end
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment