将“clone”路由添加到现有的restful控制器

时间:2014-06-13 20:59:15

标签: ruby-on-rails-4 controller routes

我正在尝试将此方法添加到一个安静的控制器(也有以下工作方法:index,:new,:create,:edit,:update和:destroy):

class Admin::ClassSectionsController < ApplicationController
  def clone
    @class_section = ClassSection.find(params[:id])
    @class_section = ClassSection.new(@class_section.attributes)
    render :new
  end
end

以下是config / routes.rb:

Utg::Application.routes.draw do

  devise_for :users
  root to: "home#index"
  namespace :admin do
    resources :class_sections, except: [:show]
  end

  resources :class_sections, only: [:index, :show]
end

如何为'admin / class_section /:id / clone'添加路由?

1 个答案:

答案 0 :(得分:1)

namespace :admin do    
  get "class_sections/:id/clone", to: "class_sections#clone", as: "class_sections_clone"
end