From 2922e29a466ac876c4be7c7e4979167710c82c86 Mon Sep 17 00:00:00 2001 From: twata701 Date: Fri, 21 Feb 2014 01:44:41 +0900 Subject: [PATCH] add archive in sidebar --- .gitignore | 2 + app/controllers/tweets_controller.rb | 9 +++ app/helpers/tweets_helper.rb | 7 +++ app/views/layouts/home.html.erb | 81 +++++++++++++++++++++++++ app/views/layouts/tweets.html.erb | 91 ++++++++++++++++++++++++++++ nbproject/private/private.xml | 7 ++- 6 files changed, 196 insertions(+), 1 deletion(-) create mode 100644 app/views/layouts/home.html.erb create mode 100644 app/views/layouts/tweets.html.erb diff --git a/.gitignore b/.gitignore index f90475c..dfd2e20 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,5 @@ config/secrets.yml config/settings.local.yml config/settings/*.local.yml config/environments/*.local.yml + +nbproject/* diff --git a/app/controllers/tweets_controller.rb b/app/controllers/tweets_controller.rb index 3004be5..c2a44ed 100644 --- a/app/controllers/tweets_controller.rb +++ b/app/controllers/tweets_controller.rb @@ -3,6 +3,7 @@ class TweetsController < ApplicationController before_action :set_tweet, only: [:show, :edit, :update, :destroy] before_action :check_user + before_action :make_archive # GET /tweets # GET /tweets.json @@ -100,4 +101,12 @@ def check_user end end + # ユーザがログインしていなければ、ホームにリダイレクト + def make_archive + @user = current_user + @archives = @user.tweet.group("strftime('%Y%m', tweets.timestamp)") + .order("strftime('%Y%m', tweets.timestamp) desc") + .count + end + end diff --git a/app/helpers/tweets_helper.rb b/app/helpers/tweets_helper.rb index 6b7d657..f64dc6d 100644 --- a/app/helpers/tweets_helper.rb +++ b/app/helpers/tweets_helper.rb @@ -1,2 +1,9 @@ +# coding: utf-8 module TweetsHelper + def ymconv(yyyymm,cnt) + yyyy = yyyymm[0,4] + mm = yyyymm[4,2] + + return yyyy + "年" + mm + "月 (" + cnt + ")" + end end diff --git a/app/views/layouts/home.html.erb b/app/views/layouts/home.html.erb new file mode 100644 index 0000000..4f08129 --- /dev/null +++ b/app/views/layouts/home.html.erb @@ -0,0 +1,81 @@ + + + + + + + <%= content_for?(:title) ? yield(:title) : "Twice" %> + <%= csrf_meta_tags %> + + + + + <%= stylesheet_link_tag "application", :media => "all" %> + + + + <%= favicon_link_tag 'apple-touch-icon-144x144-precomposed.png', :rel => 'apple-touch-icon-precomposed', :type => 'image/png', :sizes => '144x144' %> + + + + <%= favicon_link_tag 'apple-touch-icon-114x114-precomposed.png', :rel => 'apple-touch-icon-precomposed', :type => 'image/png', :sizes => '114x114' %> + + + + <%= favicon_link_tag 'apple-touch-icon-72x72-precomposed.png', :rel => 'apple-touch-icon-precomposed', :type => 'image/png', :sizes => '72x72' %> + + + + <%= favicon_link_tag 'apple-touch-icon-precomposed.png', :rel => 'apple-touch-icon-precomposed', :type => 'image/png' %> + + + + <%= favicon_link_tag 'favicon.ico', :rel => 'shortcut icon' %> + + <%= javascript_include_tag "application" %> + + + + + +
+
+
+ <%= bootstrap_flash %> + <%= yield %> +
+
+ +
+

© Company 2014

+
+ +
+ + + diff --git a/app/views/layouts/tweets.html.erb b/app/views/layouts/tweets.html.erb new file mode 100644 index 0000000..b39ce39 --- /dev/null +++ b/app/views/layouts/tweets.html.erb @@ -0,0 +1,91 @@ + + + + + + + <%= content_for?(:title) ? yield(:title) : "Twice" %> + <%= csrf_meta_tags %> + + + + + <%= stylesheet_link_tag "application", :media => "all" %> + + + + <%= favicon_link_tag 'apple-touch-icon-144x144-precomposed.png', :rel => 'apple-touch-icon-precomposed', :type => 'image/png', :sizes => '144x144' %> + + + + <%= favicon_link_tag 'apple-touch-icon-114x114-precomposed.png', :rel => 'apple-touch-icon-precomposed', :type => 'image/png', :sizes => '114x114' %> + + + + <%= favicon_link_tag 'apple-touch-icon-72x72-precomposed.png', :rel => 'apple-touch-icon-precomposed', :type => 'image/png', :sizes => '72x72' %> + + + + <%= favicon_link_tag 'apple-touch-icon-precomposed.png', :rel => 'apple-touch-icon-precomposed', :type => 'image/png' %> + + + + <%= favicon_link_tag 'favicon.ico', :rel => 'shortcut icon' %> + + <%= javascript_include_tag "application" %> + + + + + +
+
+
+ +
+
+ <%= bootstrap_flash %> + <%= yield %> +
+
+ +
+

© Company 2014

+
+ +
+ + + diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml index 8bbfb49..708a8cc 100644 --- a/nbproject/private/private.xml +++ b/nbproject/private/private.xml @@ -11,6 +11,11 @@ - + + file:/Users/takahashi/dev/twice/app/controllers/application_controller.rb + file:/Users/takahashi/dev/twice/app/models/tweet.rb + file:/Users/takahashi/dev/twice/app/models/user.rb + file:/Users/takahashi/dev/twice/app/controllers/tweets_controller.rb +