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

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

Closed
joevandyk opened this issue May 26, 2011 · 69 comments
Closed

Comments

@joevandyk
Copy link
Contributor

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.

@joevandyk
Copy link
Contributor Author

Example: We're at http://dev.tanga.com/new-admin/admin. The Dashboard link is http://dev.tanga.com/admin. https://img.skitch.com/20110526-1j7diudrmkcjycb5dtcfu1sy8n.png

However, the links in the rest of the page (below the header navigation) work just fine: https://img.skitch.com/20110526-n9ip2qjjiixqbsa9hj6iqg342s.png. The link is http://dev.tanga.com/new-admin/admin.

@andrewcarpenter
Copy link

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
Copy link
Contributor Author

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

@joshprice
Copy link

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
Copy link
Contributor

pcreux commented Sep 27, 2011

Is this issue happening with 0.3.0?

@joshprice
Copy link

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
Copy link

jalada commented Oct 17, 2011

I'm also still getting this.

@Swartz
Copy link

Swartz commented Nov 6, 2011

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
Copy link

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
Copy link

jcraigk commented Nov 23, 2011

Also having this issue

@bluebu
Copy link

bluebu commented Nov 28, 2011

me too

as 0.3.4

@nicolai86
Copy link

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

@brendandixon
Copy link

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

@ghost ghost assigned gregbell Feb 3, 2012
@jcraigk
Copy link

jcraigk commented Feb 3, 2012

Thank you, sir!

@josecoelho
Copy link

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

@seanlinsley
Copy link
Contributor

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

@josecoelho
Copy link

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
Copy link

Any idea on @josecoelho issue? Same problem here!

@seanlinsley
Copy link
Contributor

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

@josecoelho
Copy link

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

@seanlinsley
Copy link
Contributor

What do you mean by "superior" menu items?

@josecoelho
Copy link

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
Copy link
Contributor

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
Copy link

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
Copy link
Contributor

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
Copy link

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
Copy link
Contributor

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
Copy link
Contributor

yorch commented May 24, 2013

+1

@seanlinsley
Copy link
Contributor

@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
Copy link

My apologies - it's 1.0.0 pre. I was confused by the output of gem which
on my local machine but checking the dashboard instead showed me the right
version.

On Thu, Apr 10, 2014 at 9:28 PM, Sean Linsley notifications@github.comwrote:

@siruguri https://github.com/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.

Reply to this email directly or view it on GitHubhttps://github.com//issues/101#issuecomment-40169839
.

@siruguri
Copy link

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
Copy link

kuboon commented Jun 11, 2014

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

worked for me. 1.0.0 pre with Rails 4.1.1

@harinisaladi
Copy link

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

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

@lxcodes
Copy link

lxcodes commented Aug 1, 2014

+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
Copy link

siruguri commented Aug 1, 2014

I haven't tried to get assets working - and also I switched to RailsAdmin :)

On Fri, Aug 1, 2014 at 12:10 PM, Alexander notifications@github.com wrote:

+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 https://github.com/harinisaladi, @kuboon
https://github.com/kuboon, or @siruguri https://github.com/siruguri?


Reply to this email directly or view it on GitHub
#101 (comment)
.

@patsy-issa
Copy link

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
Copy link

kuboon commented Oct 8, 2014

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

@patsy-issa
Copy link

@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
Copy link
Member

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
Copy link
Member

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
Copy link

Encountered this problem with AA 0.6.0 and Rails 3.2.

This fix:
#101 (comment)

correctly resolved the issue fo rme.

@betesh
Copy link
Contributor

betesh commented Jan 29, 2015

@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

@alfius
Copy link

alfius commented Feb 5, 2015

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
Copy link

pacuna commented Mar 31, 2015

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

@semen225
Copy link

semen225 commented Aug 6, 2015

my solution:

  • config/environment.rb
Rails.application.routes.default_url_options[:script_name] = ENV['RAILS_RELATIVE_URL_ROOT']
  • app/controller/application_controller.rb
protected
    def after_sign_in_path_for(resource)
        ENV['RAILS_RELATIVE_URL_ROOT']
    end

    def after_sign_out_path_for(resource)
        new_user_session_path
    end

    def authenticate_user!
        if user_signed_in?
            super
        else
            redirect_to new_user_session_path
        end
    end

app mounted in sub-uri "/record"

  • nginx.conf
server {
        passenger_user web;
        passenger_group web;
        listen       80;
        server_name  localhost;
        client_max_body_size 20M;
        root   /home/web/ror_apps/share/static;
        passenger_enabled on;
        passenger_base_uri /record;
        rails_spawn_method smart;
        rails_env production;

        location ~ ^/(i|js|css)/ {
            expires 1d;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

    }

@betesh
Copy link
Contributor

betesh commented Aug 6, 2015

@semen225 2 suggestions:
In authenticate_user!, right before the redirect, add this:

store_location_for(:user, request.fullpath) if request.get? && !request.xhr?

Also, after_sign_out_path_for could be more generic, so you don't have to change it if you ever add another devise model:

send("new_#{resource_or_scope}_session_path")

@ReneB
Copy link

ReneB commented Sep 1, 2016

I hope this helps someone in the future because I've been struggling with this for a bit. Especially since things like AdminComments have no associated configuration in app/admin where I can specify the url for the menu item. Moreover, I really don't feel like hardcoding the app's path into the app itself, since that is no concern of the app - I should be able to move it to a different subdirectory without rewriting my code, I think.

So what I did was this, even though it's a hack:

#Add this to app/assets/javascripts/active_admin.js.coffee, below the #= require active_admin/base line
#= require_self                                                                                    

(($) ->                                                                                            
  $(document).ready ->                                                                             
    $('#header li a').each ->                                                                      
      href = $(this).attr('href')                                                                  
      url_suffix = href.replace(/.*\/admin\//, '')                                                 

      current_location = document.location.pathname                                                
      location_prefix = current_location.replace(/admin\/?.*/, "admin/")                           

      $(this).attr('href', location_prefix + url_suffix)                                           
)(jQuery)  

That will rewrite the top bar's "href"s after the page has loaded, anchoring around the 'admin/' section of the path and assuming that everything in front of it is constant for the app. This also fixes the link to your own profile, for example, which remained broken otherwise.

edit: changed regex slightly to also work on any links that may accidentally already have been correct.

@cazzerson
Copy link

@timoschilling Recent work and documentation seem to indicate that relative_url_rootis no longer considered deprecated.

@victorlcampos
Copy link

+1

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

No branches or pull requests