سؤال

أريد:

  • كل projectpart أن تنتمي إلى المشروع.

  • كل حل تنتمي إلى projectart (وإلى المشروع من خلال أن projectpart).

  • كل صورة تنتمي إلى حل (و إلى المشروع projectpart من خلال هذا الحل.)

  • كل وثيقة تنتمي إلى الحل (وأن المشروع ، projectpart من خلال هذا الحل.)

  • كل عنوان URL إلى أن تكون قصيرة بقدر بسيط ممكن.

  • كل حالة من "projectpart" تظهر بأنه "جزء" في كل عنوان URL.(لم أستطع استدعاء نموذج "جزء" على Heroku.)

يمكن لأحد أن يقول لي لماذا هذا...

ActionController::Routing::Routes.draw do |map|
  map.resources :projects, :shallow => true do |project|
    project.resources :projectparts do |part|
      part.resources :solutions do |solution|
        solution.resources :images
        solution.resources :documents
      end
    end
  end
  map.connect ':controller/:action/:id'
  map.connect ':controller/:action/:id.:format'
end

...هو ترك مجموعة كاملة من حالات "projectpart" في عناوين المواقع...

steven-nobles-imac-200:drominay steven$ rake routes
(in /Users/steven/Drominay)

                          projects GET    /projects                                           {:controller=>"projects", :action=>"index"}
                formatted_projects GET    /projects.:format                                   {:controller=>"projects", :action=>"index"}
                                   POST   /projects                                           {:controller=>"projects", :action=>"create"}
                                   POST   /projects.:format                                   {:controller=>"projects", :action=>"create"}
                       new_project GET    /projects/new                                       {:controller=>"projects", :action=>"new"}
             formatted_new_project GET    /projects/new.:format                               {:controller=>"projects", :action=>"new"}
                      edit_project GET    /projects/:id/edit                                  {:controller=>"projects", :action=>"edit"}
            formatted_edit_project GET    /projects/:id/edit.:format                          {:controller=>"projects", :action=>"edit"}
                           project GET    /projects/:id                                       {:controller=>"projects", :action=>"show"}
                 formatted_project GET    /projects/:id.:format                               {:controller=>"projects", :action=>"show"}
                                   PUT    /projects/:id                                       {:controller=>"projects", :action=>"update"}
                                   PUT    /projects/:id.:format                               {:controller=>"projects", :action=>"update"}
                                   DELETE /projects/:id                                       {:controller=>"projects", :action=>"destroy"}
                                   DELETE /projects/:id.:format                               {:controller=>"projects", :action=>"destroy"}
              project_projectparts GET    /projects/:project_id/projectparts                  {:controller=>"projectparts", :action=>"index"}
    formatted_project_projectparts GET    /projects/:project_id/projectparts.:format          {:controller=>"projectparts", :action=>"index"}
                                   POST   /projects/:project_id/projectparts                  {:controller=>"projectparts", :action=>"create"}
                                   POST   /projects/:project_id/projectparts.:format          {:controller=>"projectparts", :action=>"create"}
           new_project_projectpart GET    /projects/:project_id/projectparts/new              {:controller=>"projectparts", :action=>"new"}
 formatted_new_project_projectpart GET    /projects/:project_id/projectparts/new.:format      {:controller=>"projectparts", :action=>"new"}
                  edit_projectpart GET    /projectparts/:id/edit                              {:controller=>"projectparts", :action=>"edit"}
        formatted_edit_projectpart GET    /projectparts/:id/edit.:format                      {:controller=>"projectparts", :action=>"edit"}
                       projectpart GET    /projectparts/:id                                   {:controller=>"projectparts", :action=>"show"}
             formatted_projectpart GET    /projectparts/:id.:format                           {:controller=>"projectparts", :action=>"show"}
                                   PUT    /projectparts/:id                                   {:controller=>"projectparts", :action=>"update"}
                                   PUT    /projectparts/:id.:format                           {:controller=>"projectparts", :action=>"update"}
                                   DELETE /projectparts/:id                                   {:controller=>"projectparts", :action=>"destroy"}
                                   DELETE /projectparts/:id.:format                           {:controller=>"projectparts", :action=>"destroy"}
             projectpart_solutions GET    /projectparts/:projectpart_id/solutions             {:controller=>"solutions", :action=>"index"}
   formatted_projectpart_solutions GET    /projectparts/:projectpart_id/solutions.:format     {:controller=>"solutions", :action=>"index"}
                                   POST   /projectparts/:projectpart_id/solutions             {:controller=>"solutions", :action=>"create"}
                                   POST   /projectparts/:projectpart_id/solutions.:format     {:controller=>"solutions", :action=>"create"}
          new_projectpart_solution GET    /projectparts/:projectpart_id/solutions/new         {:controller=>"solutions", :action=>"new"}
formatted_new_projectpart_solution GET    /projectparts/:projectpart_id/solutions/new.:format {:controller=>"solutions", :action=>"new"}
                     edit_solution GET    /solutions/:id/edit                                 {:controller=>"solutions", :action=>"edit"}
           formatted_edit_solution GET    /solutions/:id/edit.:format                         {:controller=>"solutions", :action=>"edit"}
                          solution GET    /solutions/:id                                      {:controller=>"solutions", :action=>"show"}
                formatted_solution GET    /solutions/:id.:format                              {:controller=>"solutions", :action=>"show"}
                                   PUT    /solutions/:id                                      {:controller=>"solutions", :action=>"update"}
                                   PUT    /solutions/:id.:format                              {:controller=>"solutions", :action=>"update"}
                                   DELETE /solutions/:id                                      {:controller=>"solutions", :action=>"destroy"}
                                   DELETE /solutions/:id.:format                              {:controller=>"solutions", :action=>"destroy"}
                   solution_images GET    /solutions/:solution_id/images                      {:controller=>"images", :action=>"index"}
         formatted_solution_images GET    /solutions/:solution_id/images.:format              {:controller=>"images", :action=>"index"}
                                   POST   /solutions/:solution_id/images                      {:controller=>"images", :action=>"create"}
                                   POST   /solutions/:solution_id/images.:format              {:controller=>"images", :action=>"create"}
                new_solution_image GET    /solutions/:solution_id/images/new                  {:controller=>"images", :action=>"new"}
      formatted_new_solution_image GET    /solutions/:solution_id/images/new.:format          {:controller=>"images", :action=>"new"}
                        edit_image GET    /images/:id/edit                                    {:controller=>"images", :action=>"edit"}
              formatted_edit_image GET    /images/:id/edit.:format                            {:controller=>"images", :action=>"edit"}
                             image GET    /images/:id                                         {:controller=>"images", :action=>"show"}
                   formatted_image GET    /images/:id.:format                                 {:controller=>"images", :action=>"show"}
                                   PUT    /images/:id                                         {:controller=>"images", :action=>"update"}
                                   PUT    /images/:id.:format                                 {:controller=>"images", :action=>"update"}
                                   DELETE /images/:id                                         {:controller=>"images", :action=>"destroy"}
                                   DELETE /images/:id.:format                                 {:controller=>"images", :action=>"destroy"}
                solution_documents GET    /solutions/:solution_id/documents                   {:controller=>"documents", :action=>"index"}
      formatted_solution_documents GET    /solutions/:solution_id/documents.:format           {:controller=>"documents", :action=>"index"}
                                   POST   /solutions/:solution_id/documents                   {:controller=>"documents", :action=>"create"}
                                   POST   /solutions/:solution_id/documents.:format           {:controller=>"documents", :action=>"create"}
             new_solution_document GET    /solutions/:solution_id/documents/new               {:controller=>"documents", :action=>"new"}
   formatted_new_solution_document GET    /solutions/:solution_id/documents/new.:format       {:controller=>"documents", :action=>"new"}
                     edit_document GET    /documents/:id/edit                                 {:controller=>"documents", :action=>"edit"}
           formatted_edit_document GET    /documents/:id/edit.:format                         {:controller=>"documents", :action=>"edit"}
                          document GET    /documents/:id                                      {:controller=>"documents", :action=>"show"}
                formatted_document GET    /documents/:id.:format                              {:controller=>"documents", :action=>"show"}
                                   PUT    /documents/:id                                      {:controller=>"documents", :action=>"update"}
                                   PUT    /documents/:id.:format                              {:controller=>"documents", :action=>"update"}
                                   DELETE /documents/:id                                      {:controller=>"documents", :action=>"destroy"}
                                   DELETE /documents/:id.:format                              {:controller=>"documents", :action=>"destroy"}
                                          /:controller/:action/:id                            
                                          /:controller/:action/:id.:format   

و مع ذلك لا تولد الأساسية URL المساعدين مثل هذا ؟

undefined method `project_projectpart_path' for #<ActionView::Base:0x3438ffc> (ActionView::TemplateError)

راجع للشغل, كل شيء ما عدا تغيير "projectpart" إلى "جزء" في كل عنوان URL كان يعمل على ما يرام مع هذا أكثر مطول الجملة:

ActionController::Routing::Routes.draw do |map|


  map.resources :projects, :has_many => :projectparts
  map.resources :projects, :has_many => :solutions
  map.resources :projects, :has_many => :images
  map.resources :projects, :has_many => :documents
  map.resources :projectparts, :has_many => :solutions
  map.resources :projectparts, :has_many => :images
  map.resources :projectparts, :has_many => :documents
  map.resources :solutions, :has_many => :images
  map.resources :solutions, :has_many => :documents
  map.resources :images
  map.resources :documents


  map.connect ':controller/:action/:id'
  map.connect ':controller/:action/:id.:format'

end
هل كانت مفيدة؟

المحلول

الإجابة على سؤالك عن طريق الجيل :shallow => true

توفير الضحلة الخيار إنشاء أطول طرق أساليب جمع من الموارد الداخلية(s) ، مع توفير الضحلة طرق الأعضاء أساليب تلك المتداخلة الموارد(s).نلقي نظرة فاحصة على طرق إنشاء و سترى هذا.

أساسا الطرق التي تحتاج إلى معرف (تحرير,تحديث,عرض,تدمر) سوف القصيرة التي تحتوي الداخلي فقط معظم الموارد .الطرق التي لا تحتاج إلى معرف(مؤشر جديد) سوف تكون أطول قليلا ، التي تحتوي على الأصل فوري.

لا تحتاج project_projectpart_path لأن المشروع في project_projectpart يمكن أن يكون ضمنيا من المشروع جزء.بدلا من مجرد استخدام projectpart_path القائمة المشروع أجزاء.

الثاني المثال يوفر المفقودين الطرق لأنه لم يعطي الضحلة الخيار.

تغيير 'projectpart' إلى 'جزء' في عناوين بسيطة مثل إضافة :الخيار في التعريف.آسف لن تعمل مع الاختزال :has_many الإصدار

map.resources :projects, :shallow => true do |project|
  project.resources :projectparts, :as => "part" do |part|
    part.resources :solutions do |solution|
      solution.resources :images
      solution.resources :documents
    end
  end
end
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top