Changeset 1694

Show
Ignore:
Timestamp:
05/02/08 09:52:20 (2 weeks ago)
Author:
neuro
Message:

Fixes a couple of bugs, closing ticket 1224

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/app/controllers/admin/content_controller.rb

    r1688 r1694  
    1616  def list 
    1717    # Filtering articles 
    18     conditions = "`contents`.id > 0" 
     18    conditions = "contents.id > 0" 
    1919    if params[:search] 
    2020      @search = params[:search] 
  • trunk/app/controllers/admin/pages_controller.rb

    r1688 r1694  
    9090  def preview 
    9191    headers["Content-Type"] = "text/html; charset=utf-8" 
    92     @page = this_blog.pages.build(params[:page]) 
     92    @page = Page.new(params[:page]) 
    9393    data = render_to_string(:layout => "minimal") 
    9494    data = Base64.encode64(data).gsub("\n", '') 
  • trunk/app/controllers/articles_controller.rb

    r1693 r1694  
    6969 
    7070    set_headers 
    71     @comment = this_blog.comments.build(params[:comment]) 
     71    @comment = Comment.new(params[:comment]) 
    7272    @controller = self 
    7373  end 
     
    8686 
    8787  def view_page 
    88     if(@page = Page.find_by_name(params[:name].to_a.join('/'), :conditions => "published = 1")) 
     88    if(@page = Page.find_by_name(params[:name])) && @page.published? 
    8989      @page_title = @page.title 
    9090    else 
  • trunk/app/controllers/comments_controller.rb

    r1669 r1694  
    2525 
    2626    set_headers 
    27     @comment = this_blog.comments.build(params[:comment]) 
     27    @comment = Comment.new(params[:comment]) 
    2828 
    2929    render :template => 'articles/comment_preview' 
  • trunk/app/models/article.rb

    r1686 r1694  
    209209 
    210210  def self.find_by_published_at 
    211     find_by_sql("SELECT date_format(published_at, '%Y-%m') AS publication FROM contents WHERE published_at > 0 GROUP BY publication"
     211    super(:published_at
    212212  end 
    213213 
  • trunk/app/models/content.rb

    r1665 r1694  
    101101      end 
    102102    end 
     103     
     104    def find_by_published_at(column_name = :published_at) 
     105      from_where = "FROM #{self.table_name} WHERE #{column_name} > 0 AND type='#{self.name}'" 
     106 
     107      # Implement adapter-specific groupings below, or allow us to fall through to the generic ruby-side grouping 
     108       
     109      if self.connection.is_a?(ActiveRecord::ConnectionAdapters::MysqlAdapter) 
     110        # MySQL uses date_format 
     111        find_by_sql("SELECT date_format(#{column_name}, '%Y-%m') AS publication #{from_where} GROUP BY publication ORDER BY publication DESC") 
     112         
     113      elsif self.connection.is_a?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) 
     114        # PostgreSQL uses to_char 
     115        find_by_sql("SELECT to_char(#{column_name}, 'YYYY-MM') AS publication #{from_where} GROUP BY publication ORDER BY publication DESC") 
     116         
     117      else 
     118        # If we don't have an adapter-safe conversion from date -> YYYY-MM, 
     119        # we'll do the GROUP BY server-side. There won't be very many objects 
     120        # in this array anyway. 
     121        date_map = {} 
     122        dates = find_by_sql("SELECT #{column_name} AS publication #{from_where}") 
     123     
     124        dates.map! do |d| 
     125          d.publication = Time.parse(d.publication).strftime('%Y-%m') 
     126          d.freeze 
     127          if !date_map.has_key?(d.publication) 
     128            date_map[d.publication] = true 
     129            d 
     130          end 
     131        end 
     132        dates.reject!{|d| d.blank? || d.publication.blank?} 
     133        dates.sort!{|a,b| b.publication <=> a.publication} 
     134         
     135        dates 
     136      end 
     137    end 
    103138  end 
    104139 
  • trunk/app/models/page.rb

    r1686 r1694  
    2323 
    2424  def self.find_by_published_at 
    25     find_by_sql("SELECT date_format(created_at, '%Y-%m') AS publication FROM contents WHERE type = 'Page' GROUP BY publication"
     25    super(:created_at
    2626  end 
    2727