class <%= user_plural_class_name %>Controller < ApplicationController filter_access_to :all def index @<%= user_plural_name %> = <%= user_class_name %>.paginate(:per_page => 20, :page => params[:page], :conditions => search_conditions) end def show @<%= user_singular_name %> = params[:id].nil? ? @current_user : <%= user_class_name %>.find(params[:id]) end def new @<%= user_singular_name %> = <%= user_class_name %>.new end def create @<%= user_singular_name %> = <%= user_class_name %>.new(params[:user]) if @<%= user_singular_name %>.save flash[:success] = t("users.create.notice") redirect_to <%= user_plural_name %>_url else render :new end end def mass_new end def mass_create unless params[:text_area].blank? lines = params[:text_area].split("\r\n") for line in lines first_name, last_name, email, password = line.split(",") <%= user_class_name %>.create!(:first_name => first_name, :last_name => last_name, :email => email, :password => password, :password_confirmation => password) end flash[:success] = t("users.mass_create.notice") redirect_to <%= user_plural_name %>_url else flash[:error] = t("users.mass_create.error") render :mass_new end end def edit @<%= user_singular_name %> = <%= user_class_name %>.find(params[:id]) end def update @<%= user_singular_name %> = <%= user_class_name %>.find(params[:id]) @<%= user_singular_name %>.attributes = params[:<%= user_singular_name %>] if @user.save flash[:success] = t("users.update.notice") redirect_to @user else render :edit end end def destroy @<%= user_singular_name %> = <%= user_class_name %>.find(params[:id]) @<%= user_singular_name %>.destroy flash[:notice] = t("users.destroy.notice") redirect_to <%= user_plural_name %>_url end protected def search_conditions cond_params = { :q => "%#{params[:q]}%" } cond_strings = returning([]) do |strings| strings << "(<%= user_plural_name %>.first_name like :q or <%= user_plural_name %>.last_name like :q or <%= user_plural_name %>.email like :q)" unless params[:q].blank? end cond_strings.any? ? [ cond_strings.join(' and '), cond_params ] : nil end end