0

在我的 Rails 应用程序中,我呈现了所有用户的列表。

@vk.friends do |friend|
    = friend.username
    = friend.sex
    = friend.birth_date

如何制作显示男性和女性用户(friend.sex == 1女性或friend.sex == 2男性)的链接菜单?我应该使用一些 javascript 还是只使用render. 也许你可以推荐任何 jquery 插件。

谢谢!

4

1 回答 1

0

我向您推荐非常好的宝石has_scopehttps ://github.com/plataformatec/has_scope

非常容易使用,例如,让我们说 FriendsController:

class FriendsController < ApplicationController

  has_scope :sex, default: 'all' do |controller, scope, value|
    if value == 'all'
      scope.scoped
    else
      scope
    end
  end

  def index
    @friends = apply_scopes(@vk.friends).all
  end

# in index view:
= form_tag action: :index do
  - options = [ ['All', 'all'], ['Male', 1], ['Female', 2] ]
  = select_tag(:sex, options_for_select(options, params[:sex]))
  = submit_tag
于 2013-11-12T21:39:01.780 回答