Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Navigation URLs aren't generated correctly when using Passenger's RackBaseURI #101

Closed
joevandyk opened this Issue · 64 comments
@joevandyk

I have the Rails 3 application containing active_admin mounted as a suburi (i.e. http://domain.com/sub-uri/).

The links in ActiveAdmin below the navigation header work properly (http://domain.com/sub-uri/admin/path).

But the links in the header navigation section don't include the suburi. They look like http://domain.com/admin/path.

@andrewcarpenter

We definitely hit this too; I put in a quick fix that solved it for us, but the URL generation here is pretty gross.

wested@defbf6b

@joevandyk

would using logout_path not work? (or whatever it's called)

@joshprice

I've also hit this problem when mounting the app under a sub-directory on Heroku using Rack::Builder#map

map "/sub-uri" do
  run My::Application
end

All the links below the header work fine, but the tab links do not include the sub-directory as described above.

The quick fix mentioned by @andrewcarpenter will not work in Rails 3 since relative_root_url is deprecated.

This is the same issue as #280

@pcreux
Collaborator

Is this issue happening with 0.3.0?

@joshprice

I've just updated to 0.3.2 and this is still broken in my app. Has an explicit commit been made to fix this or are you just checking to see if it's still an open issue?

@jalada

I'm also still getting this.

@Swartz

Tested on 0.3.3, same issue occurring.

Have an app that is deployed in a sub-ur (http://example.com/app1/admin/) via mod_passenger's RailsBaseURI.
Top-most menu with links to dashboard, models, etc generates links without proper sub-uri
E.g. dashboard point to http://example.com/admin/dashboard instead of http://example.com/app1/admin/dashboard

@swachian

I meet the same issue as 0.3.4 is used. The result displayed in #header is really bad. How can we fix it?

@jcraigk

Also having this issue

@bluebu

me too

as 0.3.4

@nicolai86

+1
same issue but we're using nginx + unicorn for production.

@brendandixon

+2 (I have two apps) with nginx + passenger

@gregbell gregbell closed this issue from a commit
@gregbell gregbell Moved the resolving of menu items into the view.
Doing this ensures that the full Rails router has been loaded including
any scoping and RackBaseURI configurations.

Fixes #101, #960
3e7ac40
@gregbell gregbell closed this in 3e7ac40
@gregbell gregbell was assigned
@jcraigk

Thank you, sir!

@josecoelho

I'm using v 0.6.0 and having the same issue. This problem returns?

@seanlinsley
Owner

@josecoelho can you provide some more detail of what you're running into?

@josecoelho

I have deployed on a suburl via mod_passenger's RailsBaseURI.

E.g.: http://192.168.1.2/myapp/

All other links of my application, are using the correct route to suburl. But tabbed menu links have the route to the root.

I found this commit b506c2e that removes the fix made on commit that fixes this issue.

I need to configure someting else to made this work? Thanks a lot

@frangelli

Any idea on @josecoelho issue? Same problem here!

@seanlinsley
Owner

@josecoelho so it's only nested menu items whose URLs aren't in the /myapp/ namespace?

@josecoelho

No. The problem is on all superior menu items, nested or not.

@seanlinsley
Owner

What do you mean by "superior" menu items?

@josecoelho

Sorry about my english. :)

All top menu itens have the route problem on suburls.
screen shot 2013-05-20 at 11 29 37 am

It was fixed on 3e7ac40 but the fix was undone on b506c2e

Some examples of menu item definition:

ActiveAdmin.register AdminUser do
    menu :label => "Usuários"
    menu :parent => "Cadastros"
...

ActiveAdmin.register Client do
    menu :label => "Pessoas"
...
@seanlinsley
Owner

I'm still not sure what you mean. Could you provide examples of what the URLs should be, and what they are?

By top / superior menu items do you mean the parent?

menu parent: 'Cadastros'

So Cadastros would be a parent menu item, with nested / children menu items below it.

@josecoelho

Sorry about that...

On an application configured to run via mod_passenger's with RailsBaseURI as /myapp

This code:

    ActiveAdmin.register Client do
       menu :label => "Pessoas"
    end

Should result on a top menu item:

<a href="/myapp/admin/clients">Pessoas</a>

But, is ignoring RailsBaseURI configuration and rendering this:

<a href="/admin/clients">Pessoas</a>

The same problem occur with menu itens having parents.

@seanlinsley
Owner

Thanks for the added detail.

Can you see if 9b44a50 works for you? It's the commit immediately before b506c2e.

Also, instead of RailsBaseURI have you tried using RackBaseURI?

@josecoelho

Hi Daxter,

Before test 9b44a50 I've changed from RailsBaseURI to RackBaseURI with no success.

Using 9b44a50 doesn't work too. Oo

I try to use 3e7ac40 but its too old and have incompatibilities.

@seanlinsley
Owner

Since 9b44a50 doesn't work either, then that means this problem wasn't caused by b506c2e.

Earlier you said that you're running into this problem on 0.6.0; does 0.5.1 work correctly?

@yorch

+1

@yorch

Although I'm not using Passenger but Unicorn + Nginx, but facing the same problem. What finally worked for me (probably not the best approach, but I was going insane) was:

  • Run the rails server with the variable ENV['RAILS_RELATIVE_URL_ROOT'] (in my case, on the .env file because I'm using Foreman)

  • Scope all my routes (including ActiveAdmin mount) with:

    MyApp::Application.routes.draw do
      scope ENV['RAILS_RELATIVE_URL_ROOT'] || '/' do
        # All my routes
      end
    end
  • Not using any map in my config.ru file (which I tried before but ActiveAdmin was still facing the problem).
@andrey-skat

0.5.1 work correctly, problem on 0.6

@hrigu

+1
I've defined my subUri like so

config.action_controller.relative_url_root = '/app'

Since Version 0.6, the subUri is ignored, but only in the submenu entries. All other links are o.k, the logout link as well. (See #1173)

@edwja

Is there a solution for this in 0.6? We are stuck in the water on this one. We use RackBaseURI to partition our Apache server into several web apps. When we use AA, the menu items ignore the base and therefore generate the wrong URL so navigation is broken.

@seanlinsley seanlinsley reopened this
@seanlinsley
Owner

@edwja I'm not sure what's even causing the problem, so it's hard to tell what the solution is :/

Re-opening since I didn't do that earlier.

@edwja

I'm guessing it is in the bits that create the href urls in the "tabs" id of the header-items inside the header div. Those seem to be the malformed urls. I am new to AA, so I am not able to find the code that builds those urls, but it looks like the base is coded as /admin rather that base_url + /admin.

Thanks for looking. :)

@YourNameDuck

Struggled with this myself heres a workaround:

ActiveAdmin.register Client do
menu :url => "app/admin/client"
end

not sure how it will effect submenus however.

@edwja

It turns out that this is a bug in Rails 3 related to how the url builder uses the :script_name attribute for the default_url_options. My workaround is to have the following in application.rb:

Rails.application.routes.default_url_options[:script_name] = ActionController::Base.config.relative_url_root || '/'

I also have passenger.conf set with a SetEnv line in the Directory stanza for the sub-site:

SetEnv RAILS_RELATIVE_URL_ROOT=/foo

and everything works as expected.

@seanlinsley
Owner

Since this setting is no longer supported by Rails, I'm going to close this ticket.

@pruderman-ushmm

I am using 0.6.1 and Rails 4 and still running into this issue.

Is this still a problem for others? What is the correct resolution?

Is activeadmin unusable if the application is not installed in the server's root?

@seanlinsley
Owner

Using the Rails method, it works perfectly:

scope '/foo' do
  devise_for :admin_users, ActiveAdmin::Devise.config
  ActiveAdmin.routes(self)
end
@pruderman-ushmm

Not quite perfectly for me, unfortunately. When I do this, I can no longer get to the admin page (or any other part of my app). When I go to: http://domain.net/foo/admin, I get:

No route matches [GET] "/admin"
Rails.root: /data/sites/devapps/foo

In "rake routes", all of my routes now have "/foo" prepended onto them, even though "/foo" is part of my base path. This doesn't seem right. I am running several apps on this port, and anything not at /foo should not hit this app.

Please note that my apache/passenger config looks like this:

<VirtualHost *:80>
    ServerName devapps.domain.net
    ServerAlias devapps
    DocumentRoot /data/sites/devapps/public
    CustomLog /data/site-logs/devapps/access_log usertrack
    ErrorLog /data/site-logs/devapps/error_log
    RewriteEngine on
    <Directory /data/sites/devapps/public>
       Allow from all
    </Directory>

    RailsEnv development
    RackBaseURI /foo
    <Directory /data/sites/devapps/public/foo>
        Options -MultiViews
    </Directory>
    RackBaseURI /bar
    <Directory /data/sites/devapps/public/bar>
        Options -MultiViews
    </Directory>
</VirtualHost>

The only thing I could think to try is to change RackBaseURI to "/", but this means it cannot find my config.ru, so I assume this isn't correct.

Would you have any further advice on how to do this? Before making any changes, all of my other routes and path helpers seemed to be working, correctly including the "/foo". (Including the admin routes.) The only problem seems to be with the header menus in activeadmin, which seem to be ignoring the base path, even though the helpers return it correctly.

I could be missing something, but this seems to be exactly what others have been describing. Is it that activeadmin does not support being in a Rails app not installed at the URL domain root path?

Thanks!

@seanlinsley seanlinsley reopened this
@jomag

+1, I have exactly the same problem ... Rails 4 and ActiveAdmin 0.6.1

@mhutchin

+1, Same here ... ActiveAdmin 0.6.1 and Rails 4 and Rails 4.0.1.rc1

@romeuhcf

+1, Same here with rails 4, passenger.

It seems that only links to model/resource are wrong. At model index, the filter and actions links are OK, but links to associations are broken too. Menu links on the left, dashboard and models, are broken. Links at right side are ok ( current user and logout).

@romeuhcf

I may be wrong, but it seems that urls from here, are fine

  • lib/active_admin/namespace.rb: :url => proc{ url_for [active_admin_namespace.name, current_active_admin_user] rescue '#' },

But urls generated here ignore relative_url_root:

  • lib/active_admin/resource/menu.rb: :url => proc{ resource.route_collection_path(params) },
@edwja

Did you try the workaround I posted earlier? For Rails 3.2, it has been working well for me with active_admin. HTH

@seanlinsley
Owner

What needs to be done to resolve this?

@danders0n

Setting Rails.application.routes.default_url_options[:script_name] to the relative URL root path works everywhere except the redirect that occurs after logout. Problem appears to be that in this case the code is using Rails.configuration.action_controller[:relative_url_root], which is picked up from the Passenger config as it should be, in addition to the "script_name" value.

#1681

@siruguri

I can't get this to work with the solution mentioned by @danders0n - I have AA 0.6.1, and Rails 4.1, Ruby 2.1.

I did this in my config\application.rb inside the application's module:

Rails.application.routes.default_url_options[:script_name] = ActionController::Base.config.relative_url_root || '/'

and also tried setting config.relative_url_root in environments\production.rb but couldn't get the navigation URLs on my Passenger-based deployment to use the URI with the sub-path that is configured in Passenger/Apache.

@seanlinsley
Owner

@siruguri how are you using AA 0.6.1 with Rails 4.1? The 0.6.x line doesn't support Rails 4 at all.

@siruguri
@siruguri

Nrgh. My bad. I hadn't installed Polyamorous and Ransack in my Gemfile. It works after I did that. I am not sure how that mattered and why AA was working without those gems. Or it might have been some weird gem update problem - I kept getting a 0.6.1 when I did gem which but the bundle install was done pointing to master on your repo. Might have been an artefact of some config combo on my laptop.

@kuboon
Rails.application.routes.default_url_options[:script_name] = '/my_app' 

worked for me. 1.0.0 pre with Rails 4.1.1

@harinisaladi
Rails.application.routes.default_url_options[:script_name] = '/my_app' 

Works for me too, but a redirect occurs at login and logout!

@al3x-edge

+1 for Rails.application.routes.default_url_options[:script_name] = '/my_app' -- Still need to get assets working from ActiveAdmin though. Did assets (such as chosen-sprite and datepicker) work for you @harinisaladi, @kuboon, or @siruguri?

@siruguri
@orenyk orenyk referenced this issue in YaleSTC/reservations
Closed

Active Admin navbar links broken #964

@Patsy-issa

Any news on this, just ran into it, internal nav links ignore my passenger base URI and cause a 404 unless I manually add /server/ before admin.

@kuboon

@Patsy-issa Have you tried this code? #101 (comment)

@Patsy-issa

@kuboon Just added it in now, works like a charm, avoided it in the first place when I read that it broke assets. Cheers.

@timoschilling timoschilling added Routing and removed Routing labels
@timoschilling

Can someone confirm that relative_url_root works in a normal Rails App?
I have tried to set relative_url_root = "/myapp", but in a Rails scaffold all url's a not respecting relative_url_root.
I think this is not a ActiveAdmin bug, it looks like a Rails bug.

@timoschilling

Now I get a bit deeper into relative_url_root, it's deprecated and works now only for configuring rake asset:precompile. See rails/rails#2435 (comment) for details and workaround.

@armahillo

Encountered this problem with AA 0.6.0 and Rails 3.2.

This fix:
#101 (comment)

correctly resolved the issue fo rme.

@betesh

@armahillo 's solution worked for me. Actually, all I needed was the 1st part--didn't need to use SetEnv RAILS_RELATIVE_URL_ROOT=/foo. Rails 4.1.9 and activeadmin from github, commit 95127af

@alfonsocora

The only solution that worked for me with Rails 4.2 and AA from github is to manually set the menu urls like mentioned here #101 (comment)

@pacuna

yeah, not the best solution but also fixed the issue for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.