Skip to content

Commit

Permalink
user recently post
Browse files Browse the repository at this point in the history
  • Loading branch information
tadyjp committed Mar 11, 2014
1 parent 8aa1499 commit 715625b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/models/post.rb
Expand Up @@ -2,7 +2,7 @@ class Post < ActiveRecord::Base
has_many :post_tags
has_many :tags, through: :post_tags
belongs_to :author, class_name: 'User'
has_many :comments
has_many :comments, inverse_of: 'posts'

default_scope { order(:updated_at => :desc) }

Expand Down
7 changes: 6 additions & 1 deletion app/models/user.rb
Expand Up @@ -7,9 +7,13 @@ class User < ActiveRecord::Base
:recoverable, :rememberable, :trackable, :validatable
devise :omniauthable, omniauth_providers: [:google_oauth2]

has_many :posts
has_many :posts, foreign_key: 'author_id'
has_many :comments

scope :post_recently, -> {
User.joins(:posts).group('id').order('posts.updated_at desc')
}

# Device
def self.find_for_google_oauth2(access_token, signed_in_resource = nil)
info = access_token.info
Expand Down Expand Up @@ -56,4 +60,5 @@ def google_oauth_token_refresh!
google_token_expires_at: Time.now + res_json['expires_in'].seconds
)
end

end
19 changes: 13 additions & 6 deletions app/views/flow/show.html.slim
@@ -1,11 +1,18 @@
/! view:flow/show
.row

h1
| Flow
small - 最近投稿された記事

.col-xs-8 role="navigation"
#tab-list.tab-pane.active
.list-group
- @posts.each_with_index do |post, i|
a.list-group-item.post-list data-post-id=post.id href="#" = post.title
.list-group
- @posts.each_with_index do |post, i|
a.list-group-item.post-list data-post-id=post.id href="#" = post.title

.col-xs-4
#list_post
p#posts-placeholder style="color:#aaa;font-size:30px" &lt;-- Select a post...
h2
small 最近投稿したユーザー
.list-group
- User.post_recently.limit(10).each_with_index do |author, i|
a.list-group-item.post-list data-author-id=author.id href="#" = author.name

0 comments on commit 715625b

Please sign in to comment.