Rails 帮助 ActionView::Template::Error 提示:没有运算符与给定名称和参数类型匹配。您可能需要添加显式类型转换
我的 Rails 应用程序在我的语言环境机器上使用 mysql 运行良好。 但在 Heroku 上,我收到以下错误: http://pastie.org/1697772
我的 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
我的类别控制器:
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
我的模型:
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
PostgreSQL 不会原谅我的 kategori_id 是 varchar。
将其更改为整数。问题解决了。
PostgreSQL is unforgiving my kategori_id was varchar.
Changed it to be an integer. Problem solved.
这是你的问题:
我不太确定你在这里做什么,但我认为错误来自于你在同一行使用
=
和==
。您设置一个将自身与另一个变量进行比较的变量。你需要改变它,这样你就不会在那里有 == 。
Here is your problem:
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.