我有一个名为 Volunteers 的资源:
class VolunteersController < ApplicationController
before_filter :authenticate_user!
def index
#@volunteers = Volunteer.all()
@volunteers = Volunteer.paginate(:page => params[:page])
end
def show
@volunteer = Volunteer.find(params[:id])
end
def new
@volunteer = Volunteer.new
end
def create
@post = Volunteer.new(volunteer_params)
@post.save
redirect_to @post
end
def destroy
@volunteer = Volunteer.find(params[:id])
@volunteer.destroy
redirect_to :action => 'index'
end
def search
@volunteers = Volunteer.search params[:search]
end
private
def volunteer_params
params.require(:volunteer).permit(:forename, :surname)
end
end
我添加了一个名为 search 的附加操作,但在路由文件中映射它时遇到问题:
root 'home#index'
resources :volunteers
如何映射到搜索操作(包括参数)?