Commit 8d3bed34 by tady

ユーザー管理画面

parent 86f64a99
class UsersController < ApplicationController
before_action :set_user, only: [:edit, :update]
def edit
end
def update
respond_to do |format|
if @user.update(user_params)
format.html { redirect_to edit_user_path(@user), flash: { notice: 'Post 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
private
# Use callbacks to share common setup or constraints between actions.
def set_user
@user = current_user
end
def user_params
params.require(:user).permit(:nickname).to_hash
end
end
class UsersDecorator < Draper::Decorator
delegate_all
# Define presentation-specific methods here. Helpers are accessed through
# `helpers` (aka `h`). You can override attributes, for example:
#
# def created_at
# helpers.content_tag :span, class: 'time' do
# object.created_at.strftime("%a %m/%d/%y")
# end
# end
end
module UsersHelper
end
......@@ -14,6 +14,16 @@ class User < ActiveRecord::Base
User.joins(:posts).group('id').order('posts.updated_at desc')
}
######################################################################
# validations
######################################################################
validates :name, presence: true
validates :email, presence: true
validates :email, uniqueness: true
validates :nickname, presence: true
validates :nickname, format: { with: /\A[0-9A-Za-z]+\Z/i }
validates :nickname, uniqueness: true
# Device
def self.find_for_google_oauth2(access_token, signed_in_resource = nil)
info = access_token.info
......
......@@ -37,7 +37,7 @@ nav.navbar.navbar-default.navbar-fixed-top role="navigation"
| 下書き
span.badge.pull-right = current_user.decorate.draft_count
li
a Settings (todo)
a href=edit_user_path(current_user) マイページ
li.divider
li
a href=destroy_user_session_path data-method="delete" rel="nofollow" SignOut
......
#post-form
= form_for(@user) do |f|
- if @user.errors.any?
#error_explanation
h2
= pluralize(@user.errors.count, "error")
| prohibited this post from being saved:
ul
- @user.errors.full_messages.each do |msg|
li= msg
.row
.form-horizontal role="form"
.form-group
= f.label :name, '名前', class: 'col-sm-2 control-label'
.col-sm-10
= f.text_field :name, class: 'form-control', readonly: true
.form-group
= f.label :email, 'メールアドレス', class: 'col-sm-2 control-label'
.col-sm-10
= f.text_field :email, class: 'form-control', readonly: true
.form-group
= f.label :nickname, 'ニックネーム', class: 'col-sm-2 control-label'
.col-sm-10
= f.text_field :nickname, class: 'form-control'
.form-group
.col-sm-offset-2.col-sm-10
button.btn.btn-success type="submit" 保存
h1 編集
= render 'form'
<h1>Users#update</h1>
<p>Find me in app/views/users/update.html.erb</p>
......@@ -21,6 +21,7 @@ Rendezvous::Application.routes.draw do
resources :tags, :param => :name
devise_for :users, controllers: { omniauth_callbacks: 'users/omniauth_callbacks' }
resources :users, :only => [:edit, :update]
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
......
class AddNicknameToUsers < ActiveRecord::Migration
def change
add_column :users, :nickname, :string, default: '', null: false
add_index "users", ["nickname"]
end
end
......@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20140318040809) do
ActiveRecord::Schema.define(version: 20140320043116) do
create_table "comments", force: true do |t|
t.integer "author_id"
......@@ -73,9 +73,11 @@ ActiveRecord::Schema.define(version: 20140318040809) do
t.string "google_auth_token"
t.string "google_refresh_token"
t.datetime "google_token_expires_at"
t.string "nickname", default: "", null: false
end
add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree
add_index "users", ["nickname"], name: "index_users_on_nickname", using: :btree
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree
create_table "versions", force: true do |t|
......
require 'spec_helper'
describe UsersController do
describe "GET 'edit'" do
it "returns http success" do
get 'edit'
response.should be_success
end
end
describe "GET 'update'" do
it "returns http success" do
get 'update'
response.should be_success
end
end
end
require 'spec_helper'
describe UsersDecorator do
end
require 'spec_helper'
# Specs in this file have access to a helper object that includes
# the UsersHelper. For example:
#
# describe UsersHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# expect(helper.concat_strings("this","that")).to eq("this that")
# end
# end
# end
describe UsersHelper do
pending "add some examples to (or delete) #{__FILE__}"
end
require 'spec_helper'
describe "users/edit.html.erb" do
pending "add some examples to (or delete) #{__FILE__}"
end
require 'spec_helper'
describe "users/update.html.erb" do
pending "add some examples to (or delete) #{__FILE__}"
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment