Class: HomeController

Inherits:
ApplicationController show all
Defined in:
app/controllers/home_controller.rb

Instance Method Summary (collapse)

Methods inherited from ApplicationController

#is_current_user?

Instance Method Details

- (Object) index

Display the top pages on the home-page



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/home_controller.rb', line 8

def index
  @blog = Blog.public.where(:title => t(:news) ).first
  if @blog
    @postings = @blog.postings.desc(:created_at).excludes(is_draft: true)
    unless current_user
      @postings = @postings.public
    else
      @postings = @postings.addressed_to(current_user.id)
    end
    @postings = @postings.paginate(
      :page => params[:page],
      :per_page => CONSTANTS['paginate_postings_per_page'].to_i
    )
  end
  respond_to do |format|
     format.js {
       @path = blog_path(@blog, :page => (params[:page] ? (params[:page].to_i+1) : 2))
       render :index
     }
     format.html { render :index }
  end
end

- (Object) rss_feed

Respond with an atom rss-feed GET /feed



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/home_controller.rb', line 33

def rss_feed
  @feed_items = []

  Blog.public.each do |blog|
    blog.postings.rss_items.desc(:updated_at).each do |posting|
      @feed_items << FeedItem.new(posting.title, posting.body, posting.updated_at, posting_url(posting), posting)
      posting.comments.each do |comment|
        @feed_items << FeedItem.new( ("%s %% %s" % [posting.title,comment.name]), comment.comment, comment.updated_at, posting_url(posting),comment)
      end
    end
  end

  Page.rss_items.asc(:updated_at).each do |page|
    @feed_items << FeedItem.new(page.title,page.body,page.updated_at,page_url(page),page)
    page.comments.each do |comment|
      @feed_items << FeedItem.new( ("%s %% %s" % [page.title,comment.name]), comment.comment, comment.updated_at, page_url(page),comment)
    end
  end

  @feed_items.sort! {|a,b| a.updated_at <=> b.updated_at}
  @feed_items
end

- (Object) set_draft_mode

GET /draft_mode/:mode



65
66
67
68
69
# File 'app/controllers/home_controller.rb', line 65

def set_draft_mode
  change_draft_mode(params[:mode])
  target = request.env['HTTP_REFERER'] ? request.env['HTTP_REFERER'] : root_path
  redirect_to target, :notice => t(:draft_mode_switched_to, :mode => params[:mode] == "1" ? t(:is_on) : t(:is_off)).html_safe
end

- (Object) set_locale

GET /switch_locale/:locale



57
58
59
60
61
62
# File 'app/controllers/home_controller.rb', line 57

def set_locale
  I18n.locale=params[:locale].to_sym
  cookies.permanent[:lang] = params[:locale]
  target = request.env['HTTP_REFERER'] ? request.env['HTTP_REFERER'] : root_path
  redirect_to target, :notice => t(:language_switched_to, :lang => t("locales.#{params[:locale]}")).html_safe
end

- (Object) tags

GET /tag/:tag



72
73
74
75
# File 'app/controllers/home_controller.rb', line 72

def tags
  blog_ids = Blog.for_role(current_role).only(:id).map(&:id)
  @postings ||= Posting.any_in( blog_id: blog_ids).tagged_with(params[:tag]).order([:created_at, :desc])
end