问题
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