0

こんにちは、レールにコントローラーがありますが、エラーが発生します

ActiveRecord::StatementInvalid in StreamsController#front_page


Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'EPOCH FROM posts.created_at) - 1327654606)/9000) desc LIMIT 15' at line 1: SELECT  `posts`.* FROM `posts`  WHERE ((`posts`.`featured` = 1 OR `posts`.`author_id` = 5)) ORDER BY (ln( 1 + posts.likes_count) +  (EXTRACT(EPOCH FROM posts.created_at) - 1327654606)/9000) desc LIMIT 15

StreamsController#front_page は次のとおりです。

def front_page
    stream_responder do
      @stream = Stream::FrontPage.new(current_user, params[:offset])
      @stream_json = PostPresenter.collection_json(@stream.stream_posts, current_user, lite?: true, include_root: false)
    end
  end

そしてPostPresenter

require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'template_picker')

class PostPresenter
  include ActionView::Helpers::TextHelper
  attr_accessor :post, :current_user

  def initialize(post, current_user=nil)
    @post = post
    @current_user = current_user
    @person = @current_user.try(:person)
  end

  def self.collection_json(collection, current_user, opts={})
    collection.includes(:author => :profile).map {|post| self.new(post, current_user).as_json(opts)}
  end

  def as_json(options={})
    {
        :id => @post.id,
        :guid => @post.guid,
        :text => @post.raw_message,
        :plain_text => @post.plain_text,
        :public => @post.public,
        :featured => @post.featured,
        :created_at => @post.created_at,
        :staff_picked_at => @post.staff_picked_at,
        :interacted_at => @post.interacted_at,
        :tags => @post.tags.as_json,
        :tag_list => @post.tags.map(&:name).join(", "),
        :post_type => @post.post_type,
        :image_url => @post.image_url,
        :object_url => @post.object_url,
        :favorite => @post.favorite,
        :nsfw => @post.nsfw,
        :author => PersonPresenter.new(@post.author, current_user),
        :o_embed_cache => @post.o_embed_cache.try(:as_api_response, :backbone),
        :mentioned_people => [],
        :photos => @post.photos.map {|p| p.as_api_response(:backbone)},
        :frame_name => @post.frame_name || template_name,
        :parent => (options.fetch(:include_root, true) ? parent(options) : nil),
        :title => title,
        :next_post => next_post_path,
        :previous_post => previous_post_path,
        :screenshot_url => @post.screenshot_url,
        :screenshot_width => @post.screenshot_width,
        :screenshot_height => @post.screenshot_height,
        :show_screenshot => self.show_screenshot?,
        :has_gif => self.has_gif?,
        :conversation_id => @post.conversation_id,
        :interactions => options.fetch(:lite?, false) ? lite_interactions : heavy_interactions,
        :original => @post.original?
    }
  end

  def next_post_path
    Rails.application.routes.url_helpers.next_post_path(@post)
  end

  def previous_post_path
    Rails.application.routes.url_helpers.previous_post_path(@post)
  end

  def heavy_interactions
    PostInteractionPresenter.new(@post, current_user).as_json
  end

  def lite_interactions
    PostInteractionPresenter::Lite.new(@post, current_user).as_json
  end

  def title
    @post.text.present? ? truncate(@post.plain_text, :length => 118) : I18n.translate('posts.presenter.title', :name => @post.author.name)
  end

  def template_name #kill me, lol, I should be client side
    @template_name ||= TemplatePicker.new(@post).template_name
  end

  def parent(opts={})
    PostPresenter.new(@post.parent, current_user).as_json({:include_root => false}.merge(opts)) if @post.respond_to?(:parent) && @post.parent.present?
  end

  def show_screenshot?
    @post.screenshot_url.present? 
  end

  def has_gif?
    return false unless @post.photos.present?
    return 'gif' if @post.photos.detect{ |p| p.url && p.url.match(".gif") }.present?
  end

  protected

  def person
    @current_user.person
  end

  def user_signed_in?
    @current_user.present?
  end

end

どこが間違っているのかわかりません..?これについてひどく助けが必要

4

1 に答える 1

0

クエリで開いていない括弧を閉じています。

'EPOCH FROM posts.created_at) ...'
于 2012-08-22T15:59:24.610 に答える