Add interface to create and update user accounts

new_user
1resu 8 months ago
parent 5c89cf1501
commit 5f3713aecd
  1. 3
      app/assets/stylesheets/users.scss
  2. 55
      app/controllers/users_controller.rb
  3. 2
      app/helpers/users_helper.rb
  4. 1
      app/models/user.rb
  5. 4
      app/views/suppliers/index.haml
  6. 9
      app/views/users/_form.haml
  7. 2
      app/views/users/edit.haml
  8. 8
      app/views/users/index.html.haml
  9. 2
      app/views/users/new.html.haml
  10. 9
      app/views/users/show.html.haml
  11. 6
      config/routes.rb

@ -0,0 +1,3 @@
// Place all the styles related to the Users controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: https://sass-lang.com/

@ -0,0 +1,55 @@
class UsersController < ApplicationController
def new
@user=User.new
end
def create
@user=User.new(user_params)
if @user.save
render 'show'
else
redirect_to new_user_path
end
end
def edit
@user = User.find(params[:id])
end
def update
@user = User.find(params[:id])
attrs = user_params
respond_to do |format|
if @user.update(attrs)
flash[:notice] = 'Konto wurde erfolgreich aktualisiert.'
format.html { redirect_to user_url(@user) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @user.errors.to_xml }
end
end
end
def show
@user = User.find_by_id(params[:id])
end
def index
@users = User.all
end
def destroy
@user = User.find(params[:id])
@user.destroy
respond_to do |format|
format.html { redirect_to users_url }
format.xml { head :ok }
end
end
private
def user_params
params.require(:user).permit(:email, :password)
end
end

@ -0,0 +1,2 @@
module UsersHelper
end

@ -2,6 +2,7 @@ class User < ApplicationRecord
has_many :user_accesses, :dependent => :destroy
has_many :suppliers, :through => :user_accesses
attr_accessor :password
before_save :encrypt_password

@ -20,4 +20,6 @@
%br/
= link_to 'Neuer Lieferant', new_supplier_url
|
= link_to 'Konten', users_url

@ -0,0 +1,9 @@
= simple_form_for @user do |f|
= f.input :email, required: true
= f.input :password, required: true
= f.input :password_confirmation, required: true
.form-actions
= f.submit class: 'btn'
= link_to 'Zurück', users_path

@ -0,0 +1,2 @@
%h1 Konto bearbeiten
= render 'form'

@ -0,0 +1,8 @@
%h1 Konten
- for user in @users
%li
= link_to user.email, user_path(user)
%br
= link_to 'Neues Konto', new_user_url
|
= link_to 'Zurück', suppliers_path

@ -0,0 +1,2 @@
%h1 Neues Konto anlegen
= render 'form'

@ -0,0 +1,9 @@
%h1 Konto bearbeiten
= @user.email
%br
%br
= link_to 'Bearbeiten', edit_user_path(@user)
|
= link_to 'Löschen', user_path(@user), data: { confirm: 'Bist du sicher?' }, :method => :delete
|
=link_to 'Zurück', users_path

@ -1,4 +1,6 @@
Rails.application.routes.draw do
get 'users/new'
get 'users/show'
get 'log_in' => 'sessions#new', :as => :log_in
match 'log_out' => 'sessions#destroy', :as => :log_out, :via => [:get, :post]
resources :sessions, :only => [:new, :create, :destroy]
@ -15,5 +17,9 @@ Rails.application.routes.draw do
end
end
resources :users
match '/:controller(/:action(/:id))', :via => [:get, :post]
match '/users', to: 'users#index', via: 'get'
match '/users/:id', to: 'users#show', via: 'get'
end

Loading…
Cancel
Save