TrestleAdmin / trestle

A modern, responsive admin framework for Ruby on Rails
https://trestle.io
GNU Lesser General Public License v3.0
1.96k stars 177 forks source link

Rails 5 routing through engine breaking on extra params #214

Open jkolen-briq opened 5 years ago

jkolen-briq commented 5 years ago

Steps to reproduce

I'm using Trestle in a secondary engine, OurUi, that handles configuration. We'll be using it across several internal apps so we can centrally control UX. The following works fine directly with Trestle: rails generate scaffold student name:string age:integer rails generate trestle:install rails generate trestle:resource Student The following fails using the OurUi engine: rails generate scaffold student name:string age:integer rails generate trestle:resource Student when going to /admin/students with the error No route matches {:action=>"index", :controller=>"students_admin/admin", :order=>"asc", :sort=>:id} By putting some trace puts in ActionDispatch::Journey::Formatter#generate it looks like {:action=>"index", :controller=>"students_admin/admin"} matches fine. Not sure where to tell the app that the order and sort fields are ok.

System configuration

Trestle 0.8.12 Rails 5.2.3 Ruby 2.6.2

Routes

                   Prefix Verb   URI Pattern                                                                              Controller#Action
                  trestle        /admin                                                                                   Trestle::Engine
                 students GET    /students(.:format)                                                                      students#index
                          POST   /students(.:format)                                                                      students#create
              new_student GET    /students/new(.:format)                                                                  students#new
             edit_student GET    /students/:id/edit(.:format)                                                             students#edit
                  student GET    /students/:id(.:format)                                                                  students#show
                          PATCH  /students/:id(.:format)                                                                  students#update
                          PUT    /students/:id(.:format)                                                                  students#update
                          DELETE /students/:id(.:format)                                                                  students#destroy
                     root GET    /                                                                                        test#home
                 test_one GET    /test/one(.:format)                                                                      test#one
                 test_two GET    /test/two(.:format)                                                                      test#two
               test_three GET    /test/three(.:format)                                                                    test#three
                test_home GET    /test/home(.:format)                                                                     test#home
                test_solo GET    /test/solo(.:format)                                                                     test#solo
       rails_service_blob GET    /rails/active_storage/blobs/:signed_id/*filename(.:format)                               active_storage/blobs#show
rails_blob_representation GET    /rails/active_storage/representations/:signed_blob_id/:variation_key/*filename(.:format) active_storage/representations#show
       rails_disk_service GET    /rails/active_storage/disk/:encoded_key/*filename(.:format)                              active_storage/disk#show
update_rails_disk_service PUT    /rails/active_storage/disk/:encoded_token(.:format)                                      active_storage/disk#update
     rails_direct_uploads POST   /rails/active_storage/direct_uploads(.:format)                                           active_storage/direct_uploads#create

Routes for Trestle::Engine:
students_admin_index GET    /students(.:format)          students_admin/admin#index
                     POST   /students(.:format)          students_admin/admin#create
  new_students_admin GET    /students/new(.:format)      students_admin/admin#new
 edit_students_admin GET    /students/:id/edit(.:format) students_admin/admin#edit
      students_admin GET    /students/:id(.:format)      students_admin/admin#show
                     PATCH  /students/:id(.:format)      students_admin/admin#update
                     PUT    /students/:id(.:format)      students_admin/admin#update
                     DELETE /students/:id(.:format)      students_admin/admin#destroy
                root GET    /                            trestle/dashboard#index
jkolen-briq commented 5 years ago

The culprit seems to be

config.helper Rails.application.routes.url_helpers

Is there a safer way to make the main app url_helpers visible to Trestle navigation? I want to define menu entries whose paths are determined at runtime by passing a lambda for the path and then evaluating on reference in Navigation::Item.