scinote-web/app/controllers/activities_controller.rb

37 lines
854 B
Ruby
Raw Normal View History

2016-02-12 23:52:43 +08:00
class ActivitiesController < ApplicationController
include ActivityHelper
2016-02-12 23:52:43 +08:00
def index
@vars = local_vars
render json: {
more_url: local_vars.fetch(:more_activities_url),
html: render_to_string(
partial: 'list', locals: @vars, formats: :html
)
}
2016-02-12 23:52:43 +08:00
end
private
def local_vars
page = (params[:page] || 1).to_i
activities = current_user.last_activities
.page(page)
.per(Constants::ACTIVITY_AND_NOTIF_SEARCH_LIMIT)
unless activities.blank? || activities.last_page?
2018-01-06 00:08:00 +08:00
more_url = url_for(
activities_url(
format: :json,
page: page + 1,
last_activity: activities.last.id
)
)
end
{
activities: activities,
more_activities_url: more_url,
page: page
}
2016-02-12 23:52:43 +08:00
end
end