Rails help ActionView::Template::Error HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts

随声附和 提交于 2020-02-06 07:57:10

问题


My rails app runs fine on my locale machine with mysql. But on Heroku I get the following error: http://pastie.org/1697772

My kategoris_helper:

module KategorisHelper
def sortkat(column, title = nil)
  title ||= column.titleize
  css_class = column == sort_column ? "current #{sort_direction}" : nil
  direction = column == sort_column && sort_direction == "asc" ? "desc" : "asc"
  link_to title, {:sort => column, :direction => direction}, {:class => css_class}
end
end

My Kategoris controller:

class KategorisController < ApplicationController
    @kategori = Kategori.find(:first, :conditions => "cached_slug = '#{params[:id]}'")
    @konkurrencer = @kategori.konkurrancers.order(sort_column + " " + sort_direction)
    @titel = @kategori.name
  end

private

def sort_column
  Konkurrancer.column_names.include?(params[:sort]) ? params[:sort] : "created_at"
end

  def sort_direction
    %w[desc asc].include?(params[:direction]) ? params[:direction] : "desc"
  end
end

My models:

class Kategori < ActiveRecord::Base
    has_many :konkurrancers
    has_friendly_id :name, :use_slug => true
end

class Konkurrancer < ActiveRecord::Base
    belongs_to :kategori
    has_friendly_id :name, :use_slug => true
end

回答1:


PostgreSQL is unforgiving my kategori_id was varchar.

Changed it to be an integer. Problem solved.




回答2:


Here is your problem:

  css_class = column == sort_column ? "current #{sort_direction}" : nil
  direction = column == sort_column && sort_direction == "asc" ? "desc" : "asc

I'm not quite sure what your doing here but I think the error is coming from you using = and == on the same line. Your setting a variable that is comparing itself to another variable.

You ned to change it so you don't have == in there.



来源:https://stackoverflow.com/questions/5384982/rails-help-actionviewtemplateerror-hint-no-operator-matches-the-given-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!