Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

user admin skeleton added

  • Loading branch information...
commit ed2f3933f6f11836aeec3b4c3aa153d3fff5a981 1 parent 4c1b1b3
Aliaxandr Rahalevich authored
83 app/controllers/users_controller.rb
View
@@ -0,0 +1,83 @@
+class UsersController < ApplicationController
+ # GET /users
+ # GET /users.json
+ def index
+ @users = User.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @users }
+ end
+ end
+
+ # GET /users/1
+ # GET /users/1.json
+ def show
+ @user = User.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @user }
+ end
+ end
+
+ # GET /users/new
+ # GET /users/new.json
+ def new
+ @user = User.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render json: @user }
+ end
+ end
+
+ # GET /users/1/edit
+ def edit
+ @user = User.find(params[:id])
+ end
+
+ # POST /users
+ # POST /users.json
+ def create
+ @user = User.new(params[:user])
+
+ respond_to do |format|
+ if @user.save
+ format.html { redirect_to @user, notice: 'User was successfully created.' }
+ format.json { render json: @user, status: :created, location: @user }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @user.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /users/1
+ # PUT /users/1.json
+ def update
+ @user = User.find(params[:id])
+
+ respond_to do |format|
+ if @user.update_attributes(params[:user])
+ format.html { redirect_to @user, notice: 'User was successfully updated.' }
+ format.json { head :no_content }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @user.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /users/1
+ # DELETE /users/1.json
+ def destroy
+ @user = User.find(params[:id])
+ @user.destroy
+
+ respond_to do |format|
+ format.html { redirect_to users_url }
+ format.json { head :no_content }
+ end
+ end
+end
2  app/helpers/users_helper.rb
View
@@ -0,0 +1,2 @@
+module UsersHelper
+end
87 app/views/users/_form.html.erb
View
@@ -0,0 +1,87 @@
+<%= form_for @user, :html => { :class => 'form-horizontal' } do |f| %>
+ <fieldset>
+ <legend><%= controller.action_name.capitalize %> /User</legend>
+
+ <div class="control-group">
+ <%= f.label :nickname, :class => 'control-label' %>
+ <div class="controls">
+ <%= f.text_field :nickname, :class => 'text_field' %>
+ </div>
+ </div>
+
+ <div class="control-group">
+ <%= f.label :first_name, :class => 'control-label' %>
+ <div class="controls">
+ <%= f.text_field :first_name, :class => 'text_field' %>
+ </div>
+ </div>
+
+ <div class="control-group">
+ <%= f.label :middle_name, :class => 'control-label' %>
+ <div class="controls">
+ <%= f.text_field :middle_name, :class => 'text_field' %>
+ </div>
+ </div>
+
+ <div class="control-group">
+ <%= f.label :last_name, :class => 'control-label' %>
+ <div class="controls">
+ <%= f.text_field :last_name, :class => 'text_field' %>
+ </div>
+ </div>
+
+ <div class="control-group">
+ <%= f.label :phone_number, :class => 'control-label' %>
+ <div class="controls">
+ <%= f.text_field :phone_number, :class => 'text_field' %>
+ </div>
+ </div>
+
+ <div class="control-group">
+ <%= f.label :flat_number, :class => 'control-label' %>
+ <div class="controls">
+ <%= f.text_field :flat_number, :class => 'text_field' %>
+ </div>
+ </div>
+
+ <div class="control-group">
+ <%= f.label :hk_role_name, :class => 'control-label' %>
+ <div class="controls">
+ <%= f.text_field :hk_role_name, :class => 'text_field' %>
+ </div>
+ </div>
+
+ <div class="control-group">
+ <%= f.label :hk_member, :class => 'control-label' %>
+ <div class="controls">
+ <%= f.check_box :hk_member, :class => 'check_box' %>
+ </div>
+ </div>
+
+ <div class="control-group">
+ <%= f.label :tenant, :class => 'control-label' %>
+ <div class="controls">
+ <%= f.check_box :tenant, :class => 'check_box' %>
+ </div>
+ </div>
+
+ <div class="control-group">
+ <%= f.label :admin, :class => 'control-label' %>
+ <div class="controls">
+ <%= f.check_box :admin, :class => 'check_box' %>
+ </div>
+ </div>
+
+ <div class="control-group">
+ <%= f.label :email, :class => 'control-label' %>
+ <div class="controls">
+ <%= f.text_field :email, :class => 'text_field' %>
+ </div>
+ </div>
+
+ <div class="form-actions">
+ <%= f.submit nil, :class => 'btn btn-primary' %>
+ <%= link_to 'Cancel', users_path, :class => 'btn' %>
+ </div>
+ </fieldset>
+<% end %>
1  app/views/users/edit.html.erb
View
@@ -0,0 +1 @@
+<%= render :partial => 'form' %>
32 app/views/users/index.html.erb
View
@@ -0,0 +1,32 @@
+<h1>Users</h1>
+<table class="table table-striped">
+ <thead>
+ <tr>
+ <th><%= t '.nickname' %></th>
+ <th><%= t '.last_name' %></th>
+ <th><%= t '.first_name' %></th>
+ <th><%= t '.email' %></th>
+ <th><%= t '.phone_number' %></th>
+ <th><%= t '.activated' %></th>
+ <th><%= t '.hk_member' %></th>
+ <th><%= t '.admin' %></th>
+ </tr>
+ </thead>
+ <tbody>
+ <% @users.each do |user| %>
+ <tr>
+ <td><%= link_to user.nickname, user_path(user) %></td>
+ <td><%= user.last_name %></td>
+ <td><%= user.first_name %></td>
+ <td><%= user.email %></td>
+ <td>+<%= user.phone_number %></td>
+ <td><%= t ".#{user.tenant?}" %></td>
+ <td><%= t ".#{user.hk_member?}" %></td>
+ <td><%= t ".#{user.admin?}" %></td>
+ <td><%= link_to t('.edit'), edit_user_path(user), :class => 'btn btn-mini' %></td>
+ </tr>
+ <% end %>
+ </tbody>
+</table>
+
+<%= link_to 'New', new_user_path, :class => 'btn btn-primary' %>
1  app/views/users/new.html.erb
View
@@ -0,0 +1 @@
+<%= render :partial => 'form' %>
106 app/views/users/show.html.erb
View
@@ -0,0 +1,106 @@
+<h1>/User</h1>
+
+<p>
+ <b>Nickname</b><br>
+ <%= @user.nickname %>
+</p>
+
+<p>
+ <b>Email</b><br>
+ <%= @user.email %>
+</p>
+
+<p>
+ <b>First name</b><br>
+ <%= @user.first_name %>
+</p>
+
+<p>
+ <b>Middle name</b><br>
+ <%= @user.middle_name %>
+</p>
+
+<p>
+ <b>Last name</b><br>
+ <%= @user.last_name %>
+</p>
+
+<p>
+ <b>Phone number</b><br>
+ <%= @user.phone_number %>
+</p>
+
+<p>
+ <b>Flat number</b><br>
+ <%= @user.flat_number %>
+</p>
+
+<p>
+ <b>Hk role name</b><br>
+ <%= @user.hk_role_name %>
+</p>
+
+<p>
+ <b>Hk member</b><br>
+ <%= @user.hk_member %>
+</p>
+
+<p>
+ <b>Tenant</b><br>
+ <%= @user.tenant %>
+</p>
+
+<p>
+ <b>Admin</b><br>
+ <%= @user.admin %>
+</p>
+
+<p>
+ <b>Reset password sent at</b><br>
+ <%= @user.reset_password_sent_at %>
+</p>
+
+<p>
+ <b>Remember created at</b><br>
+ <%= @user.remember_created_at %>
+</p>
+
+<p>
+ <b>Sign in count</b><br>
+ <%= @user.sign_in_count %>
+</p>
+
+<p>
+ <b>Current sign in at</b><br>
+ <%= @user.current_sign_in_at %>
+</p>
+
+<p>
+ <b>Last sign in at</b><br>
+ <%= @user.last_sign_in_at %>
+</p>
+
+<p>
+ <b>Current sign in ip</b><br>
+ <%= @user.current_sign_in_ip %>
+</p>
+
+<p>
+ <b>Last sign in ip</b><br>
+ <%= @user.last_sign_in_ip %>
+</p>
+
+<p>
+ <b>Confirmed at</b><br>
+ <%= @user.confirmed_at %>
+</p>
+
+<p>
+ <b>Confirmation sent at</b><br>
+ <%= @user.confirmation_sent_at %>
+</p>
+
+<div class="form-actions">
+ <%= link_to 'Back', users_path, :class => 'btn' %>
+ <%= link_to 'Edit', edit_user_path(@user), :class => 'btn' %>
+</div>
17 config/locales/ru.yml
View
@@ -27,6 +27,23 @@ ru:
please_login_to_comment_html: 'Для того что бы оставить коментарий, Вы должны %{link}.'
sign_in: 'войти на сайт'
+ users:
+ index:
+ nickname: 'Прозвище'
+ last_name: 'Фамилия'
+ first_name: 'Имя'
+ email: 'email'
+ phone_number: 'Номер телефона'
+ activated: 'Активирован?'
+ hk_member: 'В правлении?'
+ admin: 'администратор?'
+
+ show: 'просмотреть'
+ edit: 'редактировать'
+
+ 'true': 'да'
+ 'false': 'нет'
+
layouts:
application:
useful_links: 'Полезные ссылки'
3  config/routes.rb
View
@@ -4,6 +4,9 @@
resources :news do
resources :comments
end
+
+ resources :users
+
get '/my_news' => 'news#my'
root to: 'news#index'
49 test/functional/users_controller_test.rb
View
@@ -0,0 +1,49 @@
+require 'test_helper'
+
+class UsersControllerTest < ActionController::TestCase
+ setup do
+ @user = users(:one)
+ end
+
+ test "should get index" do
+ get :index
+ assert_response :success
+ assert_not_nil assigns(:users)
+ end
+
+ test "should get new" do
+ get :new
+ assert_response :success
+ end
+
+ test "should create user" do
+ assert_difference('User.count') do
+ post :create, user: @user.attributes
+ end
+
+ assert_redirected_to user_path(assigns(:user))
+ end
+
+ test "should show user" do
+ get :show, id: @user
+ assert_response :success
+ end
+
+ test "should get edit" do
+ get :edit, id: @user
+ assert_response :success
+ end
+
+ test "should update user" do
+ put :update, id: @user, user: @user.attributes
+ assert_redirected_to user_path(assigns(:user))
+ end
+
+ test "should destroy user" do
+ assert_difference('User.count', -1) do
+ delete :destroy, id: @user
+ end
+
+ assert_redirected_to users_path
+ end
+end
4 test/unit/helpers/users_helper_test.rb
View
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class UsersHelperTest < ActionView::TestCase
+end
Please sign in to comment.
Something went wrong with that request. Please try again.