Ruby 如何在Rails中使用一个链接发送两个参数?

Ruby 如何在Rails中使用一个链接发送两个参数?,ruby,ruby-on-rails-4,activerecord,model-view-controller,associations,Ruby,Ruby On Rails 4,Activerecord,Model View Controller,Associations,我在一个Rails唤醒应用程序中工作 我有以下模型:用户、选举、参赛者 我想允许多个用户在特定选举中为参赛者投票,当用户在该选举中投票时,应该隐藏每个用户的链接 这种联系太复杂了,我搞不清楚 以下是我的联想: class User < ActiveRecord::Base has_many :contestants has_many :contestant_votes end class Contestant < ActiveRecord::Base mount_up

我在一个Rails唤醒应用程序中工作

我有以下模型:用户、选举、参赛者

我想允许多个用户在特定选举中为参赛者投票,当用户在该选举中投票时,应该隐藏每个用户的链接

这种联系太复杂了,我搞不清楚

以下是我的联想:

class User < ActiveRecord::Base

  has_many :contestants
  has_many :contestant_votes

end

class Contestant < ActiveRecord::Base
 mount_uploader :avatar, AvatarUploader
 belongs_to :user
 has_many :contestant_votes
 has_many :elections

 def votes
    read_attribute(:votes) || contestant_votes.sum(:value)
 end

end

class Election < ActiveRecord::Base
  has_many :contestants
end
class用户

如果当前用户在选举中投票给某个参赛者,如何隐藏投票链接?

您只需在
参赛者投票上添加唯一性约束即可。然后,您可以添加一个逻辑来检查当前用户和参赛者之间是否存在
参赛者投票

您可以在用户模型中添加“已投票”标志,以指示用户是否已投票。链接隐藏应该在控制器中完成。好吧,如果有新的选举呢?投票的文件仍然是假的我建议,我不完全理解你的意思,你能给我一些代码示例吗