大学のスポーツ クラブに関連付けられているユーザーをプルするチーム メンバー ページがあります。委員会のメンバーが複数のメンバーを簡単に選択できるように、各メンバーの横にチェック ボックスを作成しようとしています。送信ボタンを押すと、システムから電子メールが送信されます。
やってみ<%= 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