Rails 帮助 ActionView::Template::Error 提示:没有运算符与给定名称和参数类型匹配。您可能需要添加显式类型转换

发布于 2024-10-25 05:02:03 字数 1352 浏览 3 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不喜欢何必死缠烂打 2024-11-01 05:02:03

PostgreSQL 不会原谅我的 kategori_id 是 varchar。

将其更改为整数。问题解决了。

PostgreSQL is unforgiving my kategori_id was varchar.

Changed it to be an integer. Problem solved.

日裸衫吸 2024-11-01 05:02:03

这是你的问题:

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

我不太确定你在这里做什么,但我认为错误来自于你在同一行使用 === 。您设置一个将自身与另一个变量进行比较的变量。

你需要改变它,这样你就不会在那里有 == 。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文