1
我有一個名爲資源志願者:如何向我的路線添加其他資源操作?
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
我增加了一個額外的動作稱爲搜索,但我有問題,它在我的路線文件映射:
root 'home#index'
resources :volunteers
如何映射到搜索行動(包括參數)?
有沒有辦法提及我希望'志願者/ 1/search'映射到'search'動作? – Lokesh
@lokesh將'get'search''添加到志願者的'member do'塊中。 – Matt
謝謝!有效。 – Lokesh