diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 44c5ca4..e13a3aa 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -12,14 +12,14 @@ class ApplicationController < ActionController::Base new_user_session_path end - include OrdersHelper - include ApplicationHelper + include OrdersHelper + include ApplicationHelper - protected + protected + + def configure_permitted_parameters + devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:nickname, :name, :last_name, :password, :password_confirmation, :current_password, :avatar) } + devise_parameter_sanitizer.for(:account_update) { |u| u.permit(:nickname, :name, :last_name, :password, :password_confirmation, :current_password, :avatar) } + end - def configure_permitted_parameters - devise_parameter_sanitizer.for(:sign_up) { |u| u.permit( - :nickname, :name, :last_name, :password, :password_confirmation - ) } - end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 639080f..3ef7d1d 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -7,4 +7,11 @@ class UsersController < ApplicationController def index @users = User.all end + + def destroy + User.find(params[:id]).destroy + flash[:success] = "Succesfully removed user" + redirect_to users_path + end + end diff --git a/app/models/user.rb b/app/models/user.rb index e6311f4..f4ed8c2 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -23,6 +23,7 @@ class User < ActiveRecord::Base devise :database_authenticatable, :registerable, :rememberable, :trackable + has_attached_file :avatar, styles: { medium: "100x100>" }, default_style: :medium has_many :orders, -> { includes :products } belongs_to :dagschotel, class_name: 'Product' @@ -31,6 +32,7 @@ class User < ActiveRecord::Base validates :name, presence: true validates :last_name, presence: true validates :password, length: { in: 8..128 }, confirmation: true, on: :create + validates_attachment :avatar, presence: true, content_type: { content_type: ["image/jpeg", "image/gif", "image/png"] } def full_name "#{name} #{last_name}" diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb index 802a848..af40aa4 100644 --- a/app/views/devise/registrations/edit.html.erb +++ b/app/views/devise/registrations/edit.html.erb @@ -12,5 +12,8 @@ <%= form_password_field f, :current_password %> + <%= f.label :avatar %> + <%= f.file_field :avatar %> + <%= f.submit "Update", class: 'btn btn-primary' %> <% end %> diff --git a/app/views/devise/registrations/new.html.erb b/app/views/devise/registrations/new.html.erb index 1ab8051..d16492b 100644 --- a/app/views/devise/registrations/new.html.erb +++ b/app/views/devise/registrations/new.html.erb @@ -10,9 +10,11 @@ <%= form_password_field f, :password %> <%= form_password_field f, :password_confirmation %> -
- <%= f.submit "Sign up", class: 'btn btn-primary' %> -
+ <%= f.label :avatar %> + <%= f.file_field :avatar %> + +
+ <%= f.submit "Sign up", class: 'btn btn-primary' %> <% end %> <%= render "devise/shared/links" %> diff --git a/app/views/users/_user.html.erb b/app/views/users/_user.html.erb new file mode 100644 index 0000000..df67bcf --- /dev/null +++ b/app/views/users/_user.html.erb @@ -0,0 +1,15 @@ +
+
+ <%= image_tag user.avatar if user.avatar.exists? %> +
+

<%= user.full_name %>

+

Name: <%= user.name %>

+

Last name: <%= user.last_name %>

+

Nickname: <%= user.nickname %>

+

Balance: <%= user.balance %>

+

+ <%= link_to "Delete", user_path(user), method: :delete, class: "btn btn-danger", data: {confirm: 'Are you sure?'} %> +

+
+
+
diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index e7b22da..510cd7b 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -1,11 +1,8 @@

All users

+<%= render partial: 'flash' %> - +
+
+ <%= render @users %> +
+
diff --git a/config/routes.rb b/config/routes.rb index af59042..07b5e7e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,64 +4,9 @@ Rails.application.routes.draw do devise_for :users - resources :users, only: [:show, :index] do + resources :users do resources :orders, only: [:new, :create, :index] end resources :products - - # The priority is based upon order of creation: first created -> highest priority. - # See how all your routes lay out with "rake routes". - - # You can have the root of your site routed with "root" - # root 'welcome#index' - - # Example of regular route: - # get 'products/:id' => 'catalog#view' - - # Example of named route that can be invoked with purchase_url(id: product.id) - # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase - - # Example resource route (maps HTTP verbs to controller actions automatically): - # resources :products - - # Example resource route with options: - # resources :products do - # member do - # get 'short' - # post 'toggle' - # end - # - # collection do - # get 'sold' - # end - # end - - # Example resource route with sub-resources: - # resources :products do - # resources :comments, :sales - # resource :seller - # end - - # Example resource route with more complex sub-resources: - # resources :products do - # resources :comments - # resources :sales do - # get 'recent', on: :collection - # end - # end - - # Example resource route with concerns: - # concern :toggleable do - # post 'toggle' - # end - # resources :posts, concerns: :toggleable - # resources :photos, concerns: :toggleable - - # Example resource route within a namespace: - # namespace :admin do - # # Directs /admin/products/* to Admin::ProductsController - # # (app/controllers/admin/products_controller.rb) - # resources :products - # end end diff --git a/db/migrate/20141209204351_add_attachment_avatar_to_users.rb b/db/migrate/20141209204351_add_attachment_avatar_to_users.rb new file mode 100644 index 0000000..1d87ba8 --- /dev/null +++ b/db/migrate/20141209204351_add_attachment_avatar_to_users.rb @@ -0,0 +1,11 @@ +class AddAttachmentAvatarToUsers < ActiveRecord::Migration + def self.up + change_table :users do |t| + t.attachment :avatar + end + end + + def self.down + remove_attachment :users, :avatar + end +end diff --git a/db/schema.rb b/db/schema.rb index 90b80a5..4119d8a 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: 20141209192545) do +ActiveRecord::Schema.define(version: 20141209204351) do create_table "order_products", force: true do |t| t.integer "order_id" @@ -56,6 +56,10 @@ ActiveRecord::Schema.define(version: 20141209192545) do t.string "last_sign_in_ip" t.boolean "admin" t.integer "dagschotel_id" + t.string "avatar_file_name" + t.string "avatar_content_type" + t.integer "avatar_file_size" + t.datetime "avatar_updated_at" end end diff --git a/public/system/users/avatars/000/000/101/medium/Tomcontrastava.jpg b/public/system/users/avatars/000/000/101/medium/Tomcontrastava.jpg new file mode 100644 index 0000000..194de26 Binary files /dev/null and b/public/system/users/avatars/000/000/101/medium/Tomcontrastava.jpg differ diff --git a/public/system/users/avatars/000/000/101/original/Tomcontrastava.jpg b/public/system/users/avatars/000/000/101/original/Tomcontrastava.jpg new file mode 100644 index 0000000..3b65bf4 Binary files /dev/null and b/public/system/users/avatars/000/000/101/original/Tomcontrastava.jpg differ diff --git a/public/system/users/avatars/000/000/102/medium/Tomcontrastava.jpg b/public/system/users/avatars/000/000/102/medium/Tomcontrastava.jpg new file mode 100644 index 0000000..194de26 Binary files /dev/null and b/public/system/users/avatars/000/000/102/medium/Tomcontrastava.jpg differ diff --git a/public/system/users/avatars/000/000/102/original/Tomcontrastava.jpg b/public/system/users/avatars/000/000/102/original/Tomcontrastava.jpg new file mode 100644 index 0000000..3b65bf4 Binary files /dev/null and b/public/system/users/avatars/000/000/102/original/Tomcontrastava.jpg differ