class DiaryEntriesController < ApplicationController
+ include UserMethods
+
layout "site", :except => :rss
before_action :authorize_web
elsif params[:friends]
if current_user
@title = t ".title_friends"
- entries = DiaryEntry.where(:user_id => current_user.friends)
+ entries = DiaryEntry.where(:user => current_user.friends)
else
require_user
return
elsif params[:nearby]
if current_user
@title = t ".title_nearby"
- entries = DiaryEntry.where(:user_id => current_user.nearby)
+ entries = DiaryEntry.where(:user => current_user.nearby)
else
require_user
return
def comments
@title = t ".title", :user => @user.display_name
- conditions = { :user_id => @user }
+ comments = DiaryComment.where(:users => @user)
+ comments = comments.visible unless can? :unhidecomment, DiaryEntry
+
+ @params = params.permit(:display_name)
+
+ @comments = if params[:before]
+ comments.where("diary_comments.id < ?", params[:before]).order(:id => :desc)
+ elsif params[:after]
+ comments.where("diary_comments.id > ?", params[:after]).order(:id => :asc)
+ else
+ comments.order(:id => :desc)
+ end
- conditions[:visible] = true unless can? :unhidecomment, DiaryEntry
+ @comments = @comments.limit(20)
+ @comments = @comments.includes(:user)
+ @comments = @comments.sort.reverse
- @comment_pages, @comments = paginate(:diary_comments,
- :conditions => conditions,
- :order => "created_at DESC",
- :per_page => 20)
- @page = (params[:page] || 1).to_i
+ @newer_comments = @comments.count.positive? && comments.exists?(["diary_comments.id > ?", @comments.first.id])
+ @older_comments = @comments.count.positive? && comments.exists?(["diary_comments.id < ?", @comments.last.id])
end
private
@lon = @diary_entry.longitude
@lat = @diary_entry.latitude
@zoom = 12
- elsif !current_user.has_home?
+ elsif !current_user.home_location?
@lon = params[:lon] || -0.1
@lat = params[:lat] || 51.5
@zoom = params[:zoom] || 4