0

楷模:

 Group:
 has_many :booth_marketing_messages, :dependent => :destroy

 Booth Marketing Message:
 belongs_to :group

路线:

   resources :groups do
      member do
       get :get_group_links
        get :booth_marketing_messages
       end
      resources :booth_marketing_messages do
         member do
           match :toggle_activation
         end
      end
    end

为了创建新的展位营销信息,我有以下看法:

 <% form_for :asset, :url => (defined?(msg) ? group_booth_marketing_message_path(msg) :        
       group_booth_marketing_messages_path), :html => { :multipart => true, :method => 
      (defined?(msg) && msg ? :put : :post) } do |f| -%>
             .......

当我运行 rake 路线时:

     booth_marketing_messages_group GET  /groups/:id/booth_marketing_messages(.:format)                                        
     {:action=>"booth_marketing_messages", :controller=>"groups"}

      group_booth_marketing_messages GET 
     /groups/:group_id/booth_marketing_messages(.:format)                                  
     {:action=>"index", :controller=>"booth_marketing_messages"}

但是我的展位营销消息控制器没有索引操作。是的,这条路线不会失败,那是怎么回事?

4

1 回答 1

1

您已将路线编写为

resources :booth_marketing_messages do
     member do
       match :toggle_activation
     end
  end

因此,无论控制器中提到的任何操作或即使没有控制器,它都会创建索引、新建、创建、更新、销毁、编辑和显示等基本路由。

但是,当您转到该网址时,您将收到未找到操作错误或控制器不存在的错误。

因此,如果您想避免或不想使用默认路由,则只能在路由中使用,例如在路由中除外。

resources :products, only: [:new]

这将为仅新操作和

resources :products, except: [:new]

这将创建除新操作之外的所有路由

希望这能让你清楚

于 2013-03-22T13:18:35.300 回答