added children to users
This commit is contained in:
10
front-api/db/migrate/20150319104317_create_children.rb
Normal file
10
front-api/db/migrate/20150319104317_create_children.rb
Normal 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
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# 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
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
@@ -38,6 +38,13 @@ ActiveRecord::Schema.define(version: 20150318174814) do
|
|||||||
t.integer "order"
|
t.integer "order"
|
||||||
end
|
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|
|
create_table "delivery_destinations", force: :cascade do |t|
|
||||||
t.string "name"
|
t.string "name"
|
||||||
t.string "address"
|
t.string "address"
|
||||||
@@ -96,6 +103,7 @@ ActiveRecord::Schema.define(version: 20150318174814) do
|
|||||||
t.json "traits"
|
t.json "traits"
|
||||||
t.decimal "weight", precision: 5, scale: 3
|
t.decimal "weight", precision: 5, scale: 3
|
||||||
t.integer "special_offer_id"
|
t.integer "special_offer_id"
|
||||||
|
t.integer "supplier_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "media_types", force: :cascade do |t|
|
create_table "media_types", force: :cascade do |t|
|
||||||
@@ -145,6 +153,19 @@ ActiveRecord::Schema.define(version: 20150318174814) do
|
|||||||
t.integer "order"
|
t.integer "order"
|
||||||
end
|
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|
|
create_table "units", force: :cascade do |t|
|
||||||
t.string "name"
|
t.string "name"
|
||||||
t.string "short_name", limit: 4
|
t.string "short_name", limit: 4
|
||||||
|
|||||||
3
front-api/models/child.rb
Normal file
3
front-api/models/child.rb
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
class Child < ActiveRecord::Base
|
||||||
|
belongs_to :user
|
||||||
|
end
|
||||||
@@ -1,5 +1,9 @@
|
|||||||
class User < ActiveRecord::Base
|
class User < ActiveRecord::Base
|
||||||
has_many :carts
|
has_many :carts
|
||||||
|
has_many :children
|
||||||
|
|
||||||
|
accepts_nested_attributes_for :children
|
||||||
|
|
||||||
has_secure_password
|
has_secure_password
|
||||||
validates_presence_of :first_name, :last_name, :password, :email, :password_confirmation
|
validates_presence_of :first_name, :last_name, :password, :email, :password_confirmation
|
||||||
|
|
||||||
|
|||||||
@@ -164,14 +164,27 @@ var Register = React.createClass({
|
|||||||
},
|
},
|
||||||
register: function(e) {
|
register: function(e) {
|
||||||
if(this.validate()) {
|
if(this.validate()) {
|
||||||
|
var children = [];
|
||||||
|
if (this.state.myBabyDetailsVisible) {
|
||||||
|
children.push({
|
||||||
|
name: 'Dijete',
|
||||||
|
gender: 1
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
var user = new UserRegistration({
|
var user = new UserRegistration({
|
||||||
first_name: this.state.firstName,
|
first_name: this.state.firstName,
|
||||||
last_name: this.state.lastName,
|
last_name: this.state.lastName,
|
||||||
email: this.state.email,
|
email: this.state.email,
|
||||||
password: this.state.password,
|
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);
|
UserActions.registerUser(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,8 +276,8 @@ var Register = React.createClass({
|
|||||||
<div className="col-md-4">
|
<div className="col-md-4">
|
||||||
|
|
||||||
<button onClick={this.register} type="button" className="btn btn-default btn-lg">
|
<button onClick={this.register} type="button" className="btn btn-default btn-lg">
|
||||||
Register2
|
Registruj me
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|||||||
Reference in New Issue
Block a user