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
+
+
+ +
+ <%= render "custom_fields", :fb => custom_field %> +
+ +
+ Add Field +
+ +
+
+ <% end %> +
@@ -26,7 +26,7 @@
<%= f.text_field :age, :class => 'text_field' %> - Randomize + Randomize
@@ -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
+
+
+
+ Add Field +
+

+ + <%= render "custom_fields", :fb => custom_field %> +
+
+ <% end %> +