Class: BlogsController

Inherits:
InheritedResources::Base
  • Object
show all
Defined in:
app/controllers/blogs_controller.rb

Instance Method Summary collapse

Instance Method Details

#collectionObject



23
24
25
26
# File 'app/controllers/blogs_controller.rb', line 23

def collection
  @blogs ||= Blog.where(:user_id=>parent.id).
    paginate(:page => params[:page], :order => 'created_at DESC' )
end

#load_maybeObject



9
10
11
12
13
# File 'app/controllers/blogs_controller.rb', line 9

def load_maybe
  unless params[:user_id]
    @user = (current_user || User.root)
  end
end

#maybe_authenticateObject



33
34
35
36
37
# File 'app/controllers/blogs_controller.rb', line 33

def maybe_authenticate
  unless user_signed_in?
    authenticate_user! unless current_ability.can? :read, resource
  end
end

#parentObject



15
16
17
# File 'app/controllers/blogs_controller.rb', line 15

def parent
  @user ||= User.find(params[:user_id])
end

#tagsObject



19
20
21
# File 'app/controllers/blogs_controller.rb', line 19

def tags
  @tags ||= Blog.where(:user_id=>parent.id).tag_counts.sort{|t, u| t.count <=> u.count}
end