Sha256: 2c7eb02cdd2a135556eb17581cb150bd950bee25f818a4d6ee88728e1a8b2744

Contents?: true

Size: 1.41 KB

Versions: 3

Compression:

Stored size: 1.41 KB

Contents

class JournalController < ApplicationController
  def index
    @posts = Post.find_all(nil, 'created_at desc', @app_config['main']['num_posts'])
  end

  # View one specific post, using the post partial, and its comments using the comment
  # partial.
  def view
    begin
      @post     = Post.find(@params['id'])
      @user     = @post.user
      @comments = @post.find_all_in_comments("comment_id=0")
    rescue
      redirect_to_main
    end
  end

  # This is used for fancy URL viewing with URLs of the format /year/month/day.
  def range
    unless @params['year']
      @error = 'Invalid date.'
      render 'journal/error'
      return
    end
    if @params['day'] and !@params['month']
       @error = 'Invalid date.'
      render 'journal/error'
      return
    end

    year   = @params['year']
    fmonth = @params['month'] || '01'
    tmonth = @params['month'] ? fmonth : '12'
    fday   = @params['day'] || '01'
    tday   = @params['day'] ? fday : '31'
    
      
    if @params['day']
      tday = fday
    else # I don't like this at all.
      if tmonth == '02'
        tday = '28' 
      elsif ['01', '03', '05', '07', '08', '10', '12'].include? tmonth
        tday = '31'
      else
        tday = '30'
      end
    end

    @posts = Post.find_all(["created_at BETWEEN '%s-%s-%s 00:00:00' AND '%s-%s-%s 23:59:59'", year, fmonth, fday, year, tmonth, tday], 'created_at DESC') rescue []
    render_action 'index'
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
EliteJournal-1.9.400 app/controllers/journal_controller.rb
EliteJournal-1.9.401 app/controllers/journal_controller.rb
EliteJournal-1.9.403 app/controllers/journal_controller.rb