added children to users

This commit is contained in:
Edin Dazdarevic
2015-03-19 14:27:04 +01:00
parent 1d16951fcf
commit 69f5faffe4
5 changed files with 55 additions and 4 deletions

View File

@@ -0,0 +1,10 @@
class CreateChildren < ActiveRecord::Migration
def change
create_table :children do |t|
t.string :name
t.integer :gender
t.date :date_of_birth
t.integer :user_id
end
end
end

View File

@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150318174814) do
ActiveRecord::Schema.define(version: 20150319104317) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -38,6 +38,13 @@ ActiveRecord::Schema.define(version: 20150318174814) do
t.integer "order"
end
create_table "children", force: :cascade do |t|
t.string "name"
t.integer "gender"
t.date "date_of_birth"
t.integer "user_id"
end
create_table "delivery_destinations", force: :cascade do |t|
t.string "name"
t.string "address"
@@ -96,6 +103,7 @@ ActiveRecord::Schema.define(version: 20150318174814) do
t.json "traits"
t.decimal "weight", precision: 5, scale: 3
t.integer "special_offer_id"
t.integer "supplier_id"
end
create_table "media_types", force: :cascade do |t|
@@ -145,6 +153,19 @@ ActiveRecord::Schema.define(version: 20150318174814) do
t.integer "order"
end
create_table "suppliers", force: :cascade do |t|
t.string "name"
t.string "address"
t.string "postal_code"
t.string "town"
t.string "phone"
t.string "contact_person"
t.string "email"
t.text "note"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "units", force: :cascade do |t|
t.string "name"
t.string "short_name", limit: 4

View File

@@ -0,0 +1,3 @@
class Child < ActiveRecord::Base
belongs_to :user
end

View File

@@ -1,5 +1,9 @@
class User < ActiveRecord::Base
has_many :carts
has_many :children
accepts_nested_attributes_for :children
has_secure_password
validates_presence_of :first_name, :last_name, :password, :email, :password_confirmation

View File

@@ -164,14 +164,27 @@ var Register = React.createClass({
},
register: function(e) {
if(this.validate()) {
var children = [];
if (this.state.myBabyDetailsVisible) {
children.push({
name: 'Dijete',
gender: 1
});
}
var user = new UserRegistration({
first_name: this.state.firstName,
last_name: this.state.lastName,
email: this.state.email,
password: this.state.password,
password_confirmation: this.state.passwordConfirmation
password_confirmation: this.state.passwordConfirmation,
children_attributes : children
});
// need to add info about child
UserActions.registerUser(user);
}
@@ -263,8 +276,8 @@ var Register = React.createClass({
<div className="col-md-4">
<button onClick={this.register} type="button" className="btn btn-default btn-lg">
Register2
</button>
Registruj me
</button>
</div>
</div>
</fieldset>