tricknotes / ember-cli-rails

Unify your EmberCLI and Rails Workflows
http://thoughtbot.github.io/ember-cli-rails/
MIT License
713 stars 205 forks source link

Mount admin interface and frontend app together #458

Closed daoanhnhat1995 closed 8 years ago

daoanhnhat1995 commented 8 years ago

I have a ember app using ember-cli-rails to serve my ember app's index page but at the same time, I also have a admin app using thoughtbot's administrate gem. The problem is that the mount_ember_app would route everything to the ember app so I can't route to both ember app and server admin UI at the same time. Is there a way to mount to both apps? the admin one can be on a admin.myapp ? Or should the admin app be completely separate from spa ember app?

seanpdoyle commented 8 years ago

@daoanhnhat1995 thanks for opening this issue.

Could you share the important parts of a snippet of your config/routes.rb file?

seanpdoyle commented 8 years ago

In the mean time, you could try mounting the administrate routes before the mount_ember_app call, and make sure that you move the mount_ember_app call to the bottom of your routes file, below everything else so that the catchall route's wildcard doesn't affect any of your routes.

daoanhnhat1995 commented 8 years ago

@seanpdoyle This is my config/routes.rb

mount_ember_app :frontend, to:'/',controller: "application",action: "frontend_index"

namespace :admin do
    constraints subdomain: "admin" do
        resources :categories
        resources :brands
        resources :recommends
        resources :reviews
        root to: "brands#index"
    end
end

I'm using thoughtbot's administrate gem, I also tried to mount_ember_app at the bottom, it looks like whichever app is placed first will work while the other one doesnt. It might be something about mounting engine that I'm not familiar with because I can have my json api routes declared any where within routes.rb and still works.

seanpdoyle commented 8 years ago

@daoanhnhat1995 what happens when you swap the order of the mount_ember_app and the namespace declarations?

daoanhnhat1995 commented 8 years ago

If I swap them, the namespace admin routes work and the ember app doesnt. For example,

namespace :admin do
    constraints subdomain: "admin" do
        resources :categories
        resources :brands
        resources :recommends
        resources :reviews
        root to: "brands#index"
    end
end
namespace :api do 
    namespace :v2 do
        resources :categories, only: [:index,:show]
        resources :quotes
        resources :recommends, only:[:create]
        resources :reviews, only: [:create]
        resources :brands, only: [:index,:show]
    end
end
mount_ember_app :frontend, to:'/',controller: "application",action: "frontend_index"

The admin app works, ember app doesnt work. But the api routes work for all cases

seanpdoyle commented 8 years ago
controller: "application",action: "frontend_index"

This strikes me as odd and against some conventions.

The controller: "application" part routes the request to the ApplicationController (which is usually a an ancestor of most controllers).

The action: "frontend_index" part routes the request to ApplicationController#frontend_index, a method which doesn't normally exist.

Have you considered creating a FrontendController and routing the request through the index action?

That would more closely adhere to Rails' conventions, and it avoids serving requests through the ApplicationController, which might be causing an issue.

seanpdoyle commented 8 years ago

Closing due to inactivity.

@daoanhnhat1995 if you're still experiencing this issue, please respond to https://github.com/thoughtbot/ember-cli-rails/issues/458#issuecomment-226996897 and we'll reopen.