trestle
trestle copied to clipboard
Routing error with Rails 5 API mode
Trying to integrate trestle with a rails 5 API app. I added the necessary middlewares, but I keep on getting this error when trying to load /admin. Is there a fix for this?
Showing /Users/alecrubin/.rvm/gems/ruby-2.4.2/gems/trestle-0.8.7/app/views/trestle/resource/index.html.erb where line #4 raised:
No route matches {:action=>"new", :controller=>"items_admin/admin"}
Hi @alecrubin. Have you made any changes to your config/initializers/trestle.rb
or admin file, or are they basically pristine from the generator? Anything running like spring that may be interfering with reloading?
Are you able to try creating a fresh Rails app, copy the relevant models across and see if it still occurs?
@alecrubin I run into the same issue, have you found any solution yet ? @spohlenz ?
running rails routes
gives the following output:
Prefix Verb URI Pattern Controller#Action
trestle /admin Trestle::Engine
api_v1_posts GET /api/v1/posts(.:format) api/v1/posts#index
POST /api/v1/posts(.:format) api/v1/posts#create
api_v1_post GET /api/v1/posts/:id(.:format) api/v1/posts#show
PATCH /api/v1/posts/:id(.:format) api/v1/posts#update
PUT /api/v1/posts/:id(.:format) api/v1/posts#update
DELETE /api/v1/posts/:id(.:format) api/v1/posts#destroy
Routes for Trestle::Engine:
posts_admin_index GET /posts(.:format) posts_admin/admin#index
POST /posts(.:format) posts_admin/admin#create
posts_admin GET /posts/:id(.:format) posts_admin/admin#show
PATCH /posts/:id(.:format) posts_admin/admin#update
PUT /posts/:id(.:format) posts_admin/admin#update
DELETE /posts/:id(.:format) posts_admin/admin#destroy
root GET / trestle/dashboard#index
I just created a fresh app and a Post
model with it.
@JulienCorb I have been able to replicate this, although I haven't been able to look into it any further than that. I'm also unsure whether it is reasonable to expect an admin engine to run okay within an API-only app -- hopefully it ends up being an easy solve so that it can be supported. However I'm not particularly familiar with the api_only mode in Rails.
@spohlenz Thank you for your answer; I think adding a new
route for Trestle::Engine would solve this; But I don't know where I should add this route.
The only problem here I guess is that a rails API-only does not have any new
method or route taken into account by default.
Are you solve this issue?
I solved this Issues by adding the missing routes and the middlewares:
- add to config/application.rb the following lines inside the class
config.middleware.use ActionDispatch::Flash
config.middleware.use Rack::MethodOverride
config.middleware.use ActionDispatch::Cookies
config.middleware.use ActionDispatch::Session::CookieStore
- then at the beginning of routes.rb add you routes for you models
Trestle::Engine.routes.draw do
resources :foos, only: %i[new edit], module: 'foos_admin', controller: 'admin'
end
This issue should go to the wiki
@brunitob thanks!
Hey! Im having this error and unfortunately @brunitob 's solution isnt fixing it for me. Any more codified solution to using this with rails in the api only? if I comment out config.api_only = true
obviously it renders properly