Commit 715625b7 by tady

user recently post

parent 8aa14994
...@@ -2,7 +2,7 @@ class Post < ActiveRecord::Base ...@@ -2,7 +2,7 @@ class Post < ActiveRecord::Base
has_many :post_tags has_many :post_tags
has_many :tags, through: :post_tags has_many :tags, through: :post_tags
belongs_to :author, class_name: 'User' belongs_to :author, class_name: 'User'
has_many :comments has_many :comments, inverse_of: 'posts'
default_scope { order(:updated_at => :desc) } default_scope { order(:updated_at => :desc) }
......
...@@ -7,9 +7,13 @@ class User < ActiveRecord::Base ...@@ -7,9 +7,13 @@ class User < ActiveRecord::Base
:recoverable, :rememberable, :trackable, :validatable :recoverable, :rememberable, :trackable, :validatable
devise :omniauthable, omniauth_providers: [:google_oauth2] devise :omniauthable, omniauth_providers: [:google_oauth2]
has_many :posts has_many :posts, foreign_key: 'author_id'
has_many :comments has_many :comments
scope :post_recently, -> {
User.joins(:posts).group('id').order('posts.updated_at desc')
}
# Device # Device
def self.find_for_google_oauth2(access_token, signed_in_resource = nil) def self.find_for_google_oauth2(access_token, signed_in_resource = nil)
info = access_token.info info = access_token.info
...@@ -56,4 +60,5 @@ class User < ActiveRecord::Base ...@@ -56,4 +60,5 @@ class User < ActiveRecord::Base
google_token_expires_at: Time.now + res_json['expires_in'].seconds google_token_expires_at: Time.now + res_json['expires_in'].seconds
) )
end end
end end
/! view:flow/show /! view:flow/show
.row .row
h1
| Flow
small - 最近投稿された記事
.col-xs-8 role="navigation" .col-xs-8 role="navigation"
#tab-list.tab-pane.active
.list-group .list-group
- @posts.each_with_index do |post, i| - @posts.each_with_index do |post, i|
a.list-group-item.post-list data-post-id=post.id href="#" = post.title a.list-group-item.post-list data-post-id=post.id href="#" = post.title
.col-xs-4 .col-xs-4
#list_post h2
p#posts-placeholder style="color:#aaa;font-size:30px" &lt;-- Select a post... 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
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