TrestleAdmin / trestle

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

No route matches [GET] after changing code (helper, model) #464

Open qrooel opened 4 months ago

qrooel commented 4 months ago

Hello!

Using newest hotwire branch - I have some problems with code reloading.

Gemfile:

gem 'trestle', branch: 'hotwire', git: 'https://github.com/TrestleAdmin/trestle.git'
gem 'trestle-auth', branch: 'hotwire', git: 'https://github.com/TrestleAdmin/trestle-auth.git'

Imagine that I use this kind of code in my Trestle resource:

Trestle.resource(:attachment) do
  controller do
    def update
      instance.all_attachments
    end
  end
end

all_attachments method inside the model:

  def all_attachments
    [avatars, pictures, videos].flatten
  end

If I change anything inside all_attachments method, then I get this error: No route matches [GET] "/ta/file_uploads/1"

This happens for all the code, not only for all_attachments method. No matter where I put the code: model, helper, decorator - if I change anything, then I got an error.

I guess that I have some missing configuration on my side that reloads application code.

What I do to fix that?

Thanks for any help!

spohlenz commented 4 months ago

I've generally seen two main cases where this particular error happens No route matches [GET] ...:

1) When there is a syntax error in the _admin.rb file for the admin you are trying to access. In this case, check your rails logs a little further up to see if there are any errors prior to the error from the latest request.

In this situation, you may find restarting your rails server throws the same error, but it should pinpoint it more closely.

2) The other situation is when a table column is trying to link to another admin that may not exist. If you are using the admin_link_to helper, you can specify an admin: option explicitly. Is there something in your table block that is referencing all_attachments?

You mention using the new hotwire branch -- I'd be curious to know if the previous release didn't show these errors, as that would be surprising to me.

qrooel commented 4 months ago

Thanks for the comment!

Unfortunately none of those tips helped. ;/

Is there something in your table block that is referencing all_attachments?

No, errors could happen in almost empty resource file, like in the example above.

In the logs, after I change something in the helper/model, I see bilder.rb warnings, so I guess those errors are related with code reloading mechanism. web-1 | ActionController::RoutingError (No route matches [GET] "/ta/valuations/164"): web-1 | web-1 | /root/.asdf/installs/ruby/3.3.1/lib/ruby/gems/3.3.0/bundler/gems/trestle-8ee02e492f8e/lib/trestle/admin/builder.rb:25: warning: already initialized constant ActionsAdmin web-1 | /root/.asdf/installs/ruby/3.3.1/lib/ruby/gems/3.3.0/bundler/gems/trestle-8ee02e492f8e/lib/trestle/admin/builder.rb:25: warning: previous definition of ActionsAdmin was here web-1 | /root/.asdf/installs/ruby/3.3.1/lib/ruby/gems/3.3.0/bundler/gems/trestle-8ee02e492f8e/lib/trestle/admin/builder.rb:25: warning: already initialized constant Trestle::Auth::AccountAdmin web-1 | /root/.asdf/installs/ruby/3.3.1/lib/ruby/gems/3.3.0/bundler/gems/trestle-8ee02e492f8e/lib/trestle/admin/builder.rb:25: warning: previous definition of AccountAdmin was here web-1 | /root/.asdf/installs/ruby/3.3.1/lib/ruby/gems/3.3.0/bundler/gems/trestle-8ee02e492f8e/lib/trestle/admin/builder.rb:25: warning: already initialized constant CalculationsAdmin web-1 | /root/.asdf/installs/ruby/3.3.1/lib/ruby/gems/3.3.0/bundler/gems/trestle-8ee02e492f8e/lib/trestle/admin/builder.rb:25: warning: previous definition of CalculationsAdmin was here

I will dig some more, thanks!

spohlenz commented 4 months ago

Would you possibly be able to upload a minimal example application to GitHub that shows the issue? I'd love to get to the bottom of what is happening here but I haven't been able to reproduce it so far.