diff --git a/app/assets/stylesheets/users.css.scss b/app/assets/stylesheets/users.css.scss
index 76e5812..8e82fd4 100644
--- a/app/assets/stylesheets/users.css.scss
+++ b/app/assets/stylesheets/users.css.scss
@@ -103,3 +103,7 @@ table {
.product_dagschotel {
height: 34px;
}
+
+#users-table td {
+ vertical-align: middle;
+}
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 993c28f..8e4e7be 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -20,7 +20,7 @@ class ApplicationController < ActionController::Base
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(
- :nickname, :name, :last_name, :password, :password_confirmation,
+ :nickname, :password, :password_confirmation,
:avatar
) }
diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb
index 599bbcb..ed72a23 100644
--- a/app/controllers/orders_controller.rb
+++ b/app/controllers/orders_controller.rb
@@ -37,7 +37,7 @@ class OrdersController < ApplicationController
end
def overview
- @users = User.members.order(:name)
+ @users = User.members.order(:nickname)
end
def quickpay
diff --git a/app/models/user.rb b/app/models/user.rb
index dfe0c9b..bd7ace0 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -3,8 +3,6 @@
# Table name: users
#
# id :integer not null, primary key
-# name :string
-# last_name :string
# debt_cents :integer default("0"), not null
# nickname :string
# created_at :datetime
@@ -33,25 +31,19 @@ class User < ActiveRecord::Base
has_paper_trail only: [:debt_cents, :admin, :orders_count, :koelkast]
- has_attached_file :avatar, styles: { large: "150x150>", medium: "100x100>" }, default_style: :medium
+ has_attached_file :avatar, styles: { large: "150x150>", medium: "100x100>", small: "40x40>" }, default_style: :medium
has_many :orders, -> { includes :products }
has_many :products, through: :orders
belongs_to :dagschotel, class_name: 'Product'
validates :nickname, presence: true, uniqueness: true
- validates :name, presence: true
- validates :last_name, presence: true
validates_attachment :avatar,
presence: true,
content_type: { content_type: ["image/jpeg", "image/gif", "image/png"] }
scope :members, -> { where koelkast: false }
- def full_name
- "#{name} #{last_name}"
- end
-
def debt
self.debt_cents / 100.0
end
diff --git a/app/views/devise/registrations/new.html.erb b/app/views/devise/registrations/new.html.erb
index 5aa36e7..37eb96b 100644
--- a/app/views/devise/registrations/new.html.erb
+++ b/app/views/devise/registrations/new.html.erb
@@ -4,8 +4,6 @@
<%= f.error_messages %>
<%= f.text_field :nickname %>
- <%= f.text_field :name %>
- <%= f.text_field :last_name %>
<%= f.password_field :password %>
<%= f.password_field :password_confirmation %>
diff --git a/app/views/products/_links.html.erb b/app/views/products/_links.html.erb
new file mode 100644
index 0000000..b6d4f99
--- /dev/null
+++ b/app/views/products/_links.html.erb
@@ -0,0 +1,14 @@
+<%- if controller_name == 'products' && current_user && current_user.admin? %>
+ <%= link_to "Edit", edit_product_path(product), class: "btn btn-default" %>
+ <%= link_to "Delete", product_path(product), method: :delete, class: "btn btn-danger", data: {confirm: 'Are you sure?'} %>
+<% end -%>
+
+<%- if controller_name == 'users' %>
+
+ <% if current_user.dagschotel != product %>
+ <%= link_to "Make dagschotel", user_dagschotel_path(current_user, product), class: "btn btn-default" %>
+ <% else %>
+ <%= link_to "Huidige dagschotel", user_dagschotel_path(current_user, product), class: "btn btn-success", disabled: true %>
+ <% end %>
+
+<% end -%>
diff --git a/app/views/products/_product.html.erb b/app/views/products/_product.html.erb
index 87b021d..235c1a1 100644
--- a/app/views/products/_product.html.erb
+++ b/app/views/products/_product.html.erb
@@ -7,22 +7,7 @@
<%= product.name %>
<%= euro(product.price) %>
(In stock: <%= product.stock %>)
- <%- if controller_name == 'products' && current_user && current_user.admin? %>
-
- <%= link_to "Edit", edit_product_path(product), class: "btn btn-default" %>
- <%= link_to "Delete", product_path(product), method: :delete, class: "btn btn-danger", data: {confirm: 'Are you sure?'} %>
-
- <% end -%>
-
- <%- if controller_name == 'users' %>
-
- <% if current_user.dagschotel != product %>
- <%= link_to "Make dagschotel", user_dagschotel_path(current_user, product), class: "btn btn-default" %>
- <% else %>
- <%= link_to "Huidige dagschotel", user_dagschotel_path(current_user, product), class: "btn btn-success", disabled: true %>
- <% end %>
-
- <% end -%>
+ <%= render 'products/links', product: product %>
diff --git a/app/views/products/_product_row.html.erb b/app/views/products/_product_row.html.erb
deleted file mode 100644
index dbf84e4..0000000
--- a/app/views/products/_product_row.html.erb
+++ /dev/null
@@ -1,3 +0,0 @@
-
- - <%=(pluralize(product.count, product.name)) %>
-
diff --git a/app/views/users/_user.html.erb b/app/views/users/_user.html.erb
index 91be69c..8b1df6a 100644
--- a/app/views/users/_user.html.erb
+++ b/app/views/users/_user.html.erb
@@ -1,20 +1,19 @@
-
-
-
-
- <%= image_tag(user.avatar , class: "img-circle avatar") %>
-
Name: <%= user.name %>
-
Last name: <%= user.last_name %>
-
Nickname: <%= user.nickname %>
-
Debt: <%= euro(user.debt) %>
-
- <% if current_user.admin? %>
-
- <% end %>
-
-
+
+
+ <%= user.id %>
+ |
+
+ <%= image_tag user.avatar(:small) %>
+ |
+
+ <%= user.nickname %>
+ |
+
+ <%= euro(user.debt) %>
+ |
+ <% if current_user.admin? %>
+
+ <%= link_to "Delete", user_path(user), method: :delete, class: "btn btn-danger", data: { confirm: "Are you sure?" } %>
+ |
+ <% end %>
+
diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb
index 95c807c..65d17ed 100644
--- a/app/views/users/index.html.erb
+++ b/app/views/users/index.html.erb
@@ -1,8 +1,10 @@
-All users
-<%= render partial: 'flash' %>
-
-
- <%= render @users %>
+
+
All users
+ <%= render partial: 'flash' %>
+
+
diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb
index dbb7a52..66bc886 100644
--- a/app/views/users/show.html.erb
+++ b/app/views/users/show.html.erb
@@ -5,7 +5,7 @@
<%= link_to "[Edit dagschotel]" , user_edit_dagschotel_path(@user) if current_user == @user %>
<%= link_to "[Edit profile]" , edit_user_registration_path if current_user == @user %>
-
<%= @user.nickname %> (<%= @user.full_name %>)
+
<%= @user.nickname %>
<%= button_to "PLACE ORDER!", new_user_order_path(@user), method: :get if current_user == @user %>
DEBT: <%= euro(@user.debt) %>
@@ -16,7 +16,9 @@
Total:
- <%= @categories.map{|c| pluralize(c.count, c.category)}.join(", ")%>
Specifics:
- <%= render partial: "products/product_row", collection: @products, as: :product %>
+
+ <%= @products.map{ |p| content_tag(:li, pluralize(p.count, p.name)) }.join("\n").html_safe %>
+
All orders (<%= @user.orders_count %>)
diff --git a/db/migrate/20150319154236_remove_name_and_last_name_from_users.rb b/db/migrate/20150319154236_remove_name_and_last_name_from_users.rb
new file mode 100644
index 0000000..306ae24
--- /dev/null
+++ b/db/migrate/20150319154236_remove_name_and_last_name_from_users.rb
@@ -0,0 +1,6 @@
+class RemoveNameAndLastNameFromUsers < ActiveRecord::Migration
+ def change
+ remove_column :users, :name, :string
+ remove_column :users, :last_name, :string
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 7d91f6a..9dde761 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20150319141248) do
+ActiveRecord::Schema.define(version: 20150319154236) do
create_table "order_items", force: :cascade do |t|
t.integer "order_id"
@@ -44,8 +44,6 @@ ActiveRecord::Schema.define(version: 20150319141248) do
end
create_table "users", force: :cascade do |t|
- t.string "name"
- t.string "last_name"
t.integer "debt_cents", default: 0, null: false
t.string "nickname"
t.datetime "created_at"
diff --git a/db/seeds.rb b/db/seeds.rb
index 0a7b673..030d75a 100644
--- a/db/seeds.rb
+++ b/db/seeds.rb
@@ -38,43 +38,46 @@ end
users = [
{
nickname: 'admin',
- name: 'A.',
- last_name: 'Admin',
avatar: File.new('public/seeds/users/admin.jpg', 'r'),
admin: true
},
{
nickname: 'koelkast',
- name: 'K.',
- last_name: 'Koelkast',
avatar: File.new('public/seeds/users/admin.jpg', 'r'),
koelkast: true
},
{
nickname: 'benji',
- name: 'Benjamin',
- last_name: 'Cousaert',
avatar: File.new('public/seeds/users/benji.jpg', 'r'),
dagschotel: Product.first
},
{
nickname: 'don',
- name: 'Lorin',
- last_name: 'Werthen',
avatar: File.new('public/seeds/users/don.jpg', 'r')
},
{
nickname: 'silox',
- name: 'Tom',
- last_name: 'Naessens',
avatar: File.new('public/seeds/users/silox.jpg', 'r')
}
]
users.each do |attr|
- User.create nickname: attr[:nickname], name: attr[:name], last_name: attr[:last_name], avatar: attr[:avatar], dagschotel: attr[:dagschotel], password: DEFAULT_PASSWORD, password_confirmation: DEFAULT_PASSWORD, admin: attr[:admin] || false, koelkast: attr[:koelkast] || false
+ User.create(
+ nickname: attr[:nickname],
+ avatar: attr[:avatar],
+ dagschotel: attr[:dagschotel],
+ password: DEFAULT_PASSWORD,
+ password_confirmation: DEFAULT_PASSWORD,
+ admin: attr[:admin] || false,
+ koelkast: attr[:koelkast] || false
+ )
end
50.times do |i|
- User.create nickname: "TestUser#{i}", name: "Test", last_name: "User", avatar: users[0][:avatar], password: DEFAULT_PASSWORD, password_confirmation: DEFAULT_PASSWORD
+ User.create(
+ nickname: "TestUser#{i}",
+ avatar: users[0][:avatar],
+ password: DEFAULT_PASSWORD,
+ password_confirmation: DEFAULT_PASSWORD
+ )
end
diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml
index 8aa90d9..22defaa 100644
--- a/test/fixtures/users.yml
+++ b/test/fixtures/users.yml
@@ -3,8 +3,6 @@
# Table name: users
#
# id :integer not null, primary key
-# name :string
-# last_name :string
# debt_cents :integer default("0"), not null
# nickname :string
# created_at :datetime
diff --git a/test/models/user_test.rb b/test/models/user_test.rb
index b3bad39..7a979c3 100644
--- a/test/models/user_test.rb
+++ b/test/models/user_test.rb
@@ -3,8 +3,6 @@
# Table name: users
#
# id :integer not null, primary key
-# name :string
-# last_name :string
# debt_cents :integer default("0"), not null
# nickname :string
# created_at :datetime