我有一个团队成员页面,它通过与大学体育俱乐部相关联的用户进行筛选,我试图让它在每个成员旁边生成一个复选框,以便委员会成员可以简单地选择几个成员按下提交按钮,系统将向他们发送一封电子邮件。
我试过<%= check_box_tag(<%= render @users %>) %>
但没有任何运气
show_selection.html.rb - 这是呈现用户的页面
<% if signed_in? %>
<% if current_user.captain? %>
Welcome, select members to send a message to below
<table summary="Team members">
<tr>
<td class="main">
<% unless @users.empty? %>
<ul class="users">
<%= render @users %>
</ul>
<%= will_paginate @users %>
<% end %>
</td>
</tr>
</table>
<br>
<br>
<% else %>
<h1>An error has occured</h1>
<br>
<p>It looks like you're trying to access a restricted page <%= link_to "Please Click Here", '/' %> </p>
<% end %>
<% else %>
An error has occured
<br>
<p>It looks like you're trying to access a restricted page <%= link_to "Please Click Here", '/' %> </p>
<% end %>
users_contorller.rb
class UsersController < ApplicationController
before_filter :authenticate, :only => [:index, :edit, :update, :destroy]
before_filter :correct_user, :only => [:edit, :update]
before_filter :admin_user, :only => :destroy
def show
@user = User.find(params[:id])
@microposts = @user.microposts.paginate(:page => params[:page])
@title = @user.name
@admins = User.where(:admin => "t")
@captains = User.where(:captain => "t")
@clubs = User.where(:captain => "t")
end
def new
@user = User.new
@title = "Sign up"
end
def create
@user = User.new(params[:user])
if @user.save
sign_in @user
flash[:success] = "Welcome to University Sports!"
redirect_to @user
UserMailer.welcome_email(@user).deliver
else
@title = "Sign up"
render 'new'
end
end
def edit
@title = "Edit user"
end
def update
@user = User.find(params[:id])
if @user.update_attributes(params[:user])
flash[:success] = "Profile updated."
redirect_to @user
else
@title = "Edit user"
render 'edit'
end
end
def index
@users = User.paginate(:page => params[:page])
end
#def admins
# @users = User.admins
# render "users/index"
#end
def admins
@admins=User.where(:admin => "t")
end
def captains
@captains=User.where(:captain => "t")
end
def clubs
@clubs=User.where(:captain => "t")
end
def destroy
User.find(params[:id]).destroy
flash[:success] = "User destroyed."
redirect_to users_path
end
def following
@title = "Following"
@user = User.find(params[:id])
@users = @user.following.paginate(:page => params[:page])
render 'show_follow'
end
def followers
@title = "Followers"
@user = User.find(params[:id])
@users = @user.followers.paginate(:page => params[:page])
render 'show_follow'
end
def selection
@title = "Selection"
@user = User.find(params[:id])
@users = @user.followers.paginate(:page => params[:page])
render 'show_selection'
end
private
def authenticate
deny_access unless signed_in?
end
def correct_user
@user = User.find(params[:id])
redirect_to(root_path) unless current_user?(@user)
end
def admin_user
redirect_to(root_path) unless current_user.admin?
end
end