1
使用Rails 3.2.18
,我是新的,我試圖將此控制器添加到路由。我不確定如何做到這一點,因爲預先存在的格式與我讀過的教程不同。我不知道在哪裏添加控制器方法的名稱,以便這將是/devices/deviceTextSearch
點device_text_search
和視圖可以指它由device_text_search_path
Rails路由 - 添加控制器方法到路由
路線片段片段:
resources :devices, :only => [:index, :show, :update] do
member do
put :backup
put :refresh
end
collection do
get :find
end
控制器片斷:
# GET /devices/find
def find
device = current_domain.device.find_by_logical_name(params[:device_id].strip)
respond_to do |format|
if device.nil?
flash[:notice] = "Device '#{params[:device_id]}' was not found"
format.html { redirect_to devices_path }
else
format.html { redirect_to device_path(device) }
end
end
end
#GET /devices/deviceTextSearch
def device_text_search
if params[:q].nil?
@device_text = []
else
@device_text = DeviceTextSearch.search params[:q]
end
end