Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: No route matches {:action=>"show", :controller=>"users_admin/admin"} #70

Closed
kevinelliott opened this issue Feb 9, 2018 · 31 comments

Comments

@kevinelliott
Copy link

For some reason when I look at a show page for a Users resource, I get this routing error. This doesn't happen to any of the other managed resources in the Trestle admin panel, and they are all configured the same.

Started GET "/admin/users/24666f84-b074-40f1-802e-f94a117a3f2a" [http_request]
Processing by UsersAdmin::AdminController#show as HTML
  Parameters: {"id"=>"24666f84-b074-40f1-802e-f94a117a3f2a"} [controller_call]
  User Load (0.4ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2  [["id", "24666f84-b074-40f1-802e-f94a117a3f2a"], ["LIMIT", 1]] [sql_query]
  Rendered /Users/kevin/.rvm/gems/ruby-2.4.3@workfit/gems/trestle-0.8.6/app/views/trestle/resource/_form.html.erb (74.6ms) [template_render]
  Rendered /Users/kevin/.rvm/gems/ruby-2.4.3@workfit/gems/trestle-0.8.6/app/views/trestle/resource/show.html.erb within layouts/trestle/admin (95.1ms) [template_render]
  Rendered /Users/kevin/.rvm/gems/ruby-2.4.3@workfit/gems/trestle-0.8.6/app/views/layouts/trestle/admin.html.erb (100.3ms) [template_render]
ActionView::Template::Error (No route matches {:action=>"show", :controller=>"users_admin/admin"}) [error]
[Rollbar] Reporting exception: No route matches {:action=>"show", :controller=>"users_admin/admin"}
[Rollbar] Scheduling item
[Rollbar] Details: https://rollbar.com/instance/uuid?uuid=f75cdb15-1523-4a69-b0d2-8e0802b4f805 (only available if report was successful)
[Rollbar] Exception uuid saved in env: f75cdb15-1523-4a69-b0d2-8e0802b4f805

ActionController::UrlGenerationError - No route matches {:action=>"show", :controller=>"users_admin/admin"}:
  actionpack (5.0.6) lib/action_dispatch/journey/formatter.rb:51:in `generate'
  actionpack (5.0.6) lib/action_dispatch/routing/route_set.rb:631:in `generate'
  actionpack (5.0.6) lib/action_dispatch/routing/route_set.rb:662:in `generate'
  actionpack (5.0.6) lib/action_dispatch/routing/route_set.rb:709:in `url_for'
  trestle (0.8.6) lib/trestle/admin.rb:56:in `path'
  trestle (0.8.6) app/helpers/trestle/url_helper.rb:35:in `admin_link_to'
  trestle (0.8.6) lib/trestle/form/renderer.rb:46:in `method_missing'
  trestle (0.8.6) lib/trestle/form/automatic.rb:17:in `block (3 levels) in initialize'
  trestle (0.8.6) lib/trestle/form/renderer.rb:26:in `block in render_form'
  actionview (5.0.6) lib/action_view/helpers/capture_helper.rb:39:in `block in capture'
  actionview (5.0.6) lib/action_view/helpers/capture_helper.rb:203:in `with_output_buffer'
  actionview (5.0.6) lib/action_view/helpers/capture_helper.rb:39:in `capture'
  trestle (0.8.6) lib/trestle/form/renderer.rb:26:in `render_form'
  trestle (0.8.6) lib/trestle/form/renderer.rb:43:in `block in method_missing'
  actionview (5.0.6) lib/action_view/helpers/capture_helper.rb:39:in `block in capture'
  actionview (5.0.6) lib/action_view/helpers/capture_helper.rb:203:in `with_output_buffer'
  actionview (5.0.6) lib/action_view/helpers/capture_helper.rb:39:in `capture'
  trestle (0.8.6) lib/trestle/form/fields/static_field.rb:19:in `field'
  trestle (0.8.6) lib/trestle/form/field.rb:29:in `block in render'
  trestle (0.8.6) lib/trestle/form/field.rb:23:in `block in form_group'
  trestle (0.8.6) lib/trestle/form/fields/form_group.rb:10:in `block in render'
  actionview (5.0.6) lib/action_view/helpers/capture_helper.rb:39:in `block in capture'
  actionview (5.0.6) lib/action_view/helpers/capture_helper.rb:203:in `with_output_buffer'
  actionview (5.0.6) lib/action_view/helpers/capture_helper.rb:39:in `capture'
  actionview (5.0.6) lib/action_view/helpers/tag_helper.rb:107:in `content_tag'
  trestle (0.8.6) lib/trestle/form/field.rb:6:in `content_tag'
  trestle (0.8.6) lib/trestle/form/fields/form_group.rb:8:in `render'
  trestle (0.8.6) lib/trestle/form/builder.rb:28:in `method_missing'
  trestle (0.8.6) lib/trestle/form/field.rb:22:in `form_group'
  trestle (0.8.6) lib/trestle/form/field.rb:28:in `render'
  trestle (0.8.6) lib/trestle/form/builder.rb:28:in `method_missing'
  trestle (0.8.6) lib/trestle/form/renderer.rb:42:in `method_missing'
  trestle (0.8.6) lib/trestle/form/automatic.rb:15:in `block (2 levels) in initialize'
  trestle (0.8.6) lib/trestle/form/automatic.rb:6:in `block in initialize'
  trestle (0.8.6) lib/trestle/form/renderer.rb:26:in `block in render_form'
  actionview (5.0.6) lib/action_view/helpers/capture_helper.rb:39:in `block in capture'
  actionview (5.0.6) lib/action_view/helpers/capture_helper.rb:203:in `with_output_buffer'
Trestle.resource(:users) do
  menu do
    item :users, icon: "fa fa-users", group: :content_management
  end

  # Customize the table columns shown on the index view.
  #
  table do
    column :profile_name
    column :email
    column :admin
    column :super_user
    column :creation_source
    column :confirmed_at, align: :center
    column :tutorial_completed_at, align: :center
    column :created_at, align: :center
    column :updated_at, align: :center
    actions
  end

  search do |q|
    wq = "%#{q}%"
    User.where("id::varchar LIKE ? OR email ILIKE ?", wq, wq)
  end

  # Customize the form fields shown on the new/edit views.
  #
  # form do |user|
  #   text_field :name
  #
  #   row do
  #     col(xs: 6) { datetime_field :updated_at }
  #     col(xs: 6) { datetime_field :created_at }
  #   end
  # end

  # By default, all parameters passed to the update and create actions will be
  # permitted. If you do not have full trust in your users, you should explicitly
  # define the list of permitted parameters.
  #
  # For further information, see the Rails documentation on Strong Parameters:
  #   http://guides.rubyonrails.org/action_controller_overview.html#strong-parameters
  #
  # params do |params|
  #   params.require(:user).permit(:name, ...)
  # end
end

Thanks for your great work on this project.

@spohlenz
Copy link
Member

I'm unfortunately not able to replicate this so far. Are you able to create a minimal Rails app that exhibits the issue and upload it to GitHub?

@kevinelliott
Copy link
Author

It might very well be influenced by our User model, but I have no clear understanding of why that would affect the routes at the moment, so it makes troubleshooting this difficult. Minimal rails app is not showing this with a basic User.

@spohlenz
Copy link
Member

Can you post the output of (shell command):

$ rake routes | grep user

and from rails console:

> UsersAdmin.path(:show, id: User.first)

@kevinelliott
Copy link
Author

                              POST   /users(.:format)                      users_admin/admin#create
              new_users_admin GET    /users/new(.:format)                  users_admin/admin#new
             edit_users_admin GET    /users/:id/edit(.:format)             users_admin/admin#edit
                  users_admin GET    /users/:id(.:format)                  users_admin/admin#show
                              PATCH  /users/:id(.:format)                  users_admin/admin#update
                              PUT    /users/:id(.:format)                  users_admin/admin#update
                              DELETE /users/:id(.:format)                  users_admin/admin#destroy```

@kevinelliott
Copy link
Author

  User Load (2.6ms)  SELECT  "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT $1  [["LIMIT", 1]]
=> "/admin/users/00029911-abda-4328-8832-fca903f44a49"```

@kevinelliott
Copy link
Author

@spohlenz Any thoughts?

@spohlenz
Copy link
Member

I'm still puzzled by this. It seems like there must be something defined within your User model that is causing an issue. Is it possible to comment out most of your model code (hopefully it works at this point) and then gradually re-enable sections until you find where it breaks again?

@kevinelliott
Copy link
Author

@spohlenz Yeah, it's strange.

So I spent time commented out code in User and was never able to get it to work.

I also commented out routes that could maybe conflict, such as devise and our /users section of routes.

My team is asking me to roll back away from Trestle, but of course, I want to stay with it. Any other thoughts off hand?

@kevinelliott
Copy link
Author

I also tried renaming to people_admin.rb and using Trestle.resource(:people, model: User) but got the same error.

@svoboda-jan
Copy link
Contributor

This might be related to the ID column. What happens if the following is added to the Trestle.resource block?

controller do
  def show
    super
    self.instance.instance_eval do
      def id
        "test"
      end
    end
  end
end

@kevinelliott
Copy link
Author

@svoboda-jan Thanks for the thought. That didn't change the error unfortunately.

@svoboda-jan
Copy link
Contributor

@kevinelliott In the "minimal Rails app", do you handle IDs on models the same way as in the real app? (UUID)

@kevinelliott
Copy link
Author

I've ditched the minimal Rails app now, so I can't be sure there. But I did enable UUID.

@kevinelliott
Copy link
Author

kevinelliott commented Feb 16, 2018

The thing is, I'm using UUID on all of our other resources, and there's no issue with the Show page for them. Only User is having the problem.

@svoboda-jan
Copy link
Contributor

@kevinelliott Ok, so then maybe it is not because of (UU)IDs. Do you use something like the friendly_id gem or something like def to_param on User?

There are more tests you can do to rule out few things, for example, rename the model (class) to MyTestUser, and just set the table_name:

class MyTestUser < ActiveRecord::Base
  self.table_name = "users"
end

@kevinelliott
Copy link
Author

@svoboda-jan Nope, not overriding to_param on User, and not using friendly_id.

And it took some effort, but I renamed User to MyUser and no go:

No route matches {:action=>"show", :controller=>"my_users_admin/admin"}

@kevinelliott
Copy link
Author

I'm not sure if it helps, but I'm seeing no route_name at the first hop down into UserAdmin.path as shown in this Better Errors screenshot.

screen shot 2018-02-16 at 12 47 33 pm

@kevinelliott
Copy link
Author

And one level up:

screen shot 2018-02-16 at 12 49 13 pm

@kevinelliott
Copy link
Author

I freaking found it.

@kevinelliott
Copy link
Author

screen shot 2018-02-16 at 12 56 33 pm

In trying to build up the form, it's evaluating a relationship invited_by and then having trouble resolving this into the User and it's corresponding link, somehow.

I commented out the :invitable option to the devise definition in User and everything started working.

Thus, the invited_by_id and invited_by functionality provided by Devise is choking things up. To make matters worse, that piece of functionality is broken in our app because Devise uses int for the invited_by_id and we have not yet switched it over to use uuid. We plan on fixing this soon, but we can't disable Devise or Devise Invitable in the meantime.

Thus, I'm wonder what we can do to coax Trestle into understanding this issue.

@svoboda-jan
Copy link
Contributor

@kevinelliott Nice to hear that. :)

Why isn't it possible to disable devise_invitable? Without UUID it cannot be used anyway.

@svoboda-jan
Copy link
Contributor

svoboda-jan commented Feb 16, 2018

@kevinelliott Also where exactly does the error come from, is it the table or form block? If you define these blocks manually, you can omit the reference to this field, so trestle will not try to guess.

@kevinelliott
Copy link
Author

@svoboda-jan So, we are actively using devise_invitable, it is used by our admins to invite users to our platform. The only thing broken with it is that the invitations are not properly associated to who invited them, but otherwise it is working as expected. I can not disable that at this time. We do have someone working on changing it to work with UUID though, so eventually that will be ready. But in the meantime, our admin panel is in this semi-broken state, and I've been given a do or die on this.

@kevinelliott
Copy link
Author

It seems like (according to above screenshots) that it's when it's trying to calculate the form. So, I can try to manually define the form. We have a lot of attributes, so it will take me some time to define. Is there anyway to manually define the one field and then specify the rest to be automatically determined?

@svoboda-jan
Copy link
Contributor

@kevinelliott Not sure and don't think such functionality is available right now.

There is a workaround you could use, Trestle uses AR columns method, so you could override that in the model:

def self.columns
  super.reject { |c| c.name == "invited_by_id" }
end

@kevinelliott
Copy link
Author

kevinelliott commented Feb 16, 2018

@svoboda-jan I can't do it in the model, because then that will break our invitations panel. But, is there a way to monkey patch (I haven't said that for so long now) Trestle to do just this when it queries against the columns?

@svoboda-jan
Copy link
Contributor

@kevinelliott Sure, you could use the "new" Module#prepend, something like this in rails initializers:

Trestle::Adapters::ActiveRecordAdapter.prepend(Module.new do
  def default_attributes
    super.reject { |c| c.name == :invited_by_id }
  end
end)

@spohlenz
Copy link
Member

spohlenz commented Feb 16, 2018

Really happy to see the source of this has been found. I'll trace it further on my end to see if there's anything Trestle can do to avoid it. Thank you @svoboda-jan for your help.

Here's another way to disable specific fields within a resource:

adapter do
  def default_form_attributes
    super.reject { |column| column.name == :invited_by_id }
  end
end

@kevinelliott
Copy link
Author

And we have success! Thank you both @svoboda-jan and @spohlenz. I'm really happy that we've been able to squash this, for the interim.

@spohlenz
Copy link
Member

Okay, so this was definitely an issue within Trestle rather than you doing anything wrong. The error was occurring within the automatic form builder when a polymorphic association was blank.

It has now been fixed in 64ddc3f, so you shouldn't need the adapter customization after upgrading. I'll likely have a new gem release sometime this weekend.

Thank you for help in tracking it down.

@karan-ta
Copy link

I have bit different issue

when i do ContentsAdmin.path(:new)
it works fine.

how do i add a new route to my app through trestle engine.
so that below command works:
ContentsAdmin.path(:filter)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants