mirror of
https://github.com/indentlabs/notebook.git
synced 2025-10-26 11:19:22 +00:00
Create and associate races for each character with a race value
This commit is contained in:
parent
774d1043f6
commit
411eff77bb
@ -11,8 +11,8 @@ class CharactersController < ContentController
|
||||
[
|
||||
:universe_id, :user_id,
|
||||
:name, :age, :role, :gender, :age, :archetype, :height, :weight, :haircolor,
|
||||
:facialhair, :eyecolor, :race, :skintone, :bodytype, :identmarks, :hairstyle,
|
||||
:religion, :politics, :prejudices, :occupation, :pets, :aliases,
|
||||
:facialhair, :eyecolor, :skintone, :bodytype, :identmarks, :hairstyle,
|
||||
:religion, :politics, :prejudices, :occupation, :pets, :aliases, :race,
|
||||
:mannerisms, :birthday, :education, :background,
|
||||
:motivations, :flaws, :talents, :hobbies, :personality_type,
|
||||
:fave_color, :fave_food, :fave_possession, :fave_weapon, :fave_animal,
|
||||
|
||||
6
app/models/content_groupers/raceship.rb
Normal file
6
app/models/content_groupers/raceship.rb
Normal file
@ -0,0 +1,6 @@
|
||||
class Raceship < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
|
||||
belongs_to :character
|
||||
belongs_to :race
|
||||
end
|
||||
@ -33,6 +33,9 @@ class Character < ActiveRecord::Base
|
||||
# Items
|
||||
relates :favorite_items, with: :ownerships, where: { favorite: true }
|
||||
|
||||
# Races
|
||||
relates :races, with: :raceships
|
||||
|
||||
scope :is_public, -> { eager_load(:universe).where('characters.privacy = ? OR universes.privacy = ?', 'public', 'public') }
|
||||
|
||||
def description
|
||||
@ -55,7 +58,7 @@ class Character < ActiveRecord::Base
|
||||
},
|
||||
looks: {
|
||||
icon: 'face',
|
||||
attributes: %w(weight height haircolor hairstyle facialhair eyecolor race skintone bodytype identmarks)
|
||||
attributes: %w(weight height haircolor hairstyle facialhair eyecolor skintone bodytype identmarks races)
|
||||
},
|
||||
nature: {
|
||||
icon: 'fingerprint',
|
||||
|
||||
9
db/migrate/20161021220223_create_raceships.rb
Normal file
9
db/migrate/20161021220223_create_raceships.rb
Normal file
@ -0,0 +1,9 @@
|
||||
class CreateRaceships < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :raceships do |t|
|
||||
t.integer :user_id
|
||||
t.integer :character_id
|
||||
t.integer :race_id
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20161021211814) do
|
||||
ActiveRecord::Schema.define(version: 20161021220223) do
|
||||
|
||||
create_table "archenemyships", force: :cascade do |t|
|
||||
t.integer "user_id"
|
||||
@ -351,6 +351,12 @@ ActiveRecord::Schema.define(version: 20161021211814) do
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "raceships", force: :cascade do |t|
|
||||
t.integer "user_id"
|
||||
t.integer "character_id"
|
||||
t.integer "race_id"
|
||||
end
|
||||
|
||||
create_table "religions", force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.string "description"
|
||||
|
||||
@ -2,19 +2,16 @@ namespace :data_migrations do
|
||||
desc "Create a race for each user, for each of their characters with a `race` value"
|
||||
|
||||
task create_races_from_character_races: :environment do
|
||||
users.each do |user|
|
||||
puts "Migrating user #{user.email.split('@').first}...""
|
||||
User.all.each do |user|
|
||||
puts "Migrating user #{user.email.split('@').first}..."
|
||||
|
||||
user.characters.where.not(race: "").each do |character|
|
||||
race = character.race
|
||||
|
||||
end
|
||||
puts "\tCreating race #{race}"
|
||||
|
||||
users = User.confirmed
|
||||
puts "Going to update #{users.count} users"
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
users.each do |user|
|
||||
user.mark_newsletter_received!
|
||||
print "."
|
||||
new_race = user.races.where(name: race).first_or_create
|
||||
character.races << new_race
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user