diff --git a/app/controllers/characters_controller.rb b/app/controllers/characters_controller.rb
index 718003d0..63f6347a 100644
--- a/app/controllers/characters_controller.rb
+++ b/app/controllers/characters_controller.rb
@@ -40,6 +40,7 @@ class CharactersController < ApplicationController
# GET /characters/new.json
def new
@character = Character.new
+ @character.custom_fields.build
respond_to do |format|
format.html # new.html.erb
@@ -50,11 +51,14 @@ class CharactersController < ApplicationController
# GET /characters/1/edit
def edit
@character = Character.find(params[:id])
+ @character.custom_fields.build
end
# POST /characters
# POST /characters.json
def create
+ #raise params.to_yaml
+
@character = Character.new(params[:character])
@character.user_id = session[:user]
@character.universe = Universe.where(user_id: session[:user]).where(name: params[:character][:universe].strip).first
diff --git a/app/models/character.rb b/app/models/character.rb
index 54db6aa3..ece437d0 100644
--- a/app/models/character.rb
+++ b/app/models/character.rb
@@ -66,5 +66,6 @@ class Character
belongs_to :user
belongs_to :universe
- embeds_many :custom_fields
+ has_many :custom_fields
+ accepts_nested_attributes_for :custom_fields #, :reject_if => lambda { |a| a[:key].blank? and a[:value].blank? }
end
diff --git a/app/models/custom_field.rb b/app/models/custom_field.rb
index 27678e4c..9108df76 100644
--- a/app/models/custom_field.rb
+++ b/app/models/custom_field.rb
@@ -4,5 +4,5 @@ class CustomField
field :value, :type => String
field :section, :type => String
- embedded_in :character
+ belongs_to :character
end
diff --git a/app/views/characters/_custom_fields.html.erb b/app/views/characters/_custom_fields.html.erb
new file mode 100644
index 00000000..3e2923e6
--- /dev/null
+++ b/app/views/characters/_custom_fields.html.erb
@@ -0,0 +1,13 @@
+
+ <%= fb.text_field :key, class: "text_field control-label custom-key", placeholder: "Key" %>
+
+
+
+
+ <%= fb.text_field :value, class: "text_field custom-value", placeholder: "Value" %>
+
+
\ No newline at end of file
diff --git a/app/views/characters/_edit_form.html.erb b/app/views/characters/_edit_form.html.erb
index c58659f9..bb1b8288 100644
--- a/app/views/characters/_edit_form.html.erb
+++ b/app/views/characters/_edit_form.html.erb
@@ -38,7 +38,25 @@
- <%= render :partial => '/layouts/planning/custom_fields', :locals => { :section => "General" } %>
+
+ <%= f.fields_for :custom_fields do |custom_field| %>
+
+
Advanced: Add your own fields to this tab
+
+
+ <% end %>
+
diff --git a/app/views/characters/_form.html.erb b/app/views/characters/_form.html.erb
index 117afcdc..9d0a7481 100644
--- a/app/views/characters/_form.html.erb
+++ b/app/views/characters/_form.html.erb
@@ -5,7 +5,7 @@
@@ -26,7 +26,7 @@
@@ -38,7 +38,22 @@
- <%= render :partial => '/layouts/planning/custom_fields', :locals => { :section => "General" } %>
+
+ <%= f.fields_for :custom_fields do |custom_field| %>
+
+
Advanced: Add your own fields to this tab
+
+
+ <% end %>
+
@@ -102,10 +117,10 @@
- <%= f.label 'Best Friend', :class => 'control-label' %>
-
- <%= f.text_field :bestfriend, :class => 'text_field' %>
- <%= character_picker %>
+ <%= f.label 'Best Friend', :class => 'control-label' %>
+
+ <%= f.text_field :bestfriend, :class => 'text_field' %>
+ <%= character_picker %>
@@ -164,7 +179,7 @@
<%= f.label 'Birthplace', :class => 'control-label' %>
<%= f.text_field :birthplace, :class => 'text_field' %>
- <%= location_picker %>
+ <%= location_picker %>
@@ -194,14 +209,14 @@
<%= f.label 'Possession', :class => 'control-label' %>
<%= f.text_field :fave_possession, :class => 'text_field' %>
- <%= equipment_picker %>
+ <%= equipment_picker %>
<%= f.label 'Weapon', :class => 'control-label' %>
<%= f.text_field :fave_weapon, :class => 'text_field' %>
- <%= equipment_picker %>
+ <%= equipment_picker %>
@@ -216,38 +231,38 @@
- <%= f.label 'Father', :class => 'control-label' %>
-
- <%= f.text_field :father, :class => 'text_field' %>
- <%= character_picker %>
+ <%= f.label 'Father', :class => 'control-label' %>
+
+ <%= f.text_field :father, :class => 'text_field' %>
+ <%= character_picker %>
- <%= f.label 'Mother', :class => 'control-label' %>
-
- <%= f.text_field :mother, :class => 'text_field' %>
- <%= character_picker %>
+ <%= f.label 'Mother', :class => 'control-label' %>
+
+ <%= f.text_field :mother, :class => 'text_field' %>
+ <%= character_picker %>
- <%= f.label 'Spouse', :class => 'control-label' %>
-
- <%= f.text_field :spouse, :class => 'text_field' %>
- <%= character_picker %>
+ <%= f.label 'Spouse', :class => 'control-label' %>
+
+ <%= f.text_field :spouse, :class => 'text_field' %>
+ <%= character_picker %>
- <%= f.label 'Siblings', :class => 'control-label' %>
-
- <%= f.text_field :siblings, :class => 'text_field' %>
- <%= character_picker %>
+ <%= f.label 'Siblings', :class => 'control-label' %>
+
+ <%= f.text_field :siblings, :class => 'text_field' %>
+ <%= character_picker %>
- <%= f.label 'Archenemy', :class => 'control-label' %>
-
- <%= f.text_field :archenemy, :class => 'text_field' %>
- <%= character_picker %>
+ <%= f.label 'Archenemy', :class => 'control-label' %>
+
+ <%= f.text_field :archenemy, :class => 'text_field' %>
+ <%= character_picker %>
diff --git a/app/views/layouts/planning/_custom_fields.html.erb b/app/views/layouts/planning/_custom_fields.html.erb
index e09326c9..fecc3fa5 100644
--- a/app/views/layouts/planning/_custom_fields.html.erb
+++ b/app/views/layouts/planning/_custom_fields.html.erb
@@ -3,10 +3,6 @@
Advanced: Add your own fields to this tab
+
+
+
+
+ Add Fields
+
\ No newline at end of file