I have a rails app that is quite old and I need to get it working in a dockerized environment. I have never used ruby or rails before, so am obviously ignorant of how things work.
The rails app is run in passenger and fronted by nginx. I can get the app working correctly on the root url e.g. http://localhost/, but it needs to run under http://localhost/my-app/view.
I have added passenger config to nginx, based on the docs. Most things work correctly except for one form, the form has a controller, that works fine without sub-dir passenger config, but when I add the new config and submit the form I find my passenger_base_uri appears twice in the network request e.g.
http://localhost/my-app/view/my-app/view/explore/new?search=&area=458579%2C305178
So I can see the duplication in the URL, if I copy that URL as a curl command and remove the duplicated path, then again, it works as expected.
Looking at my nginx config for this site
location ~ ^/my-app/view(/.*|$) {
alias /var/www/html/code/public$1;
passenger_base_uri /my-app/view;
passenger_app_root /var/www/html/code;
passenger_document_root /var/www/html/code/public;
passenger_enabled on;
}
This is right out of the passenger docs I linked to above.
The form template is:
.col-md-6.col-sm-12
=form_tag( {controller: :explore, action: :new}, {method: :get, enforce_utf8: false} ) do
%fieldset
.form-group
%label{ for: "search_search" }
Sampling point name or ID
%input#search.form-control{ name: "search", id: "search", value: @exploration.user_search[:search], class: "c-constraint" }
.form-group
%label{ for: "area" }
Area
%select.form-control{ name: "area", id: "area-selections", class: "c-constraint" }
%option{ value: nil, label: "areas"}
- Areas.new.each do |area|
%option{ value: area.id, selected: @exploration.user_search.area_selected?( area.id ) }
= area.label
=submit_tag( "Find sampling points", name: nil, class: "btn btn-lg action-button c-action-submit u-margin-1-vertical" )
Any thoughts, ideas would be greatly appreciated.
I have tried tweaking the config here and there but not being experienced with passenger, I'm not really sure what to try. I also tried to introduce namespaces to the rails app, but again, due to my lack of experience, I have possibly done that wrong, I was getting errors in the logs that I couldn't decipher.
I have managed to resolve this, but forgot to post back.
It is a strange one and I don't have the full understanding to state here why it was happening.
I am locked to rails v5.2.0.
It turned out to be nginx config to passenger application container and undoing an errant
config.assets.compile = trueline in the production.rb file.Once I reset the
config.assets.compile = falseas it should have been, I then commented out thealiasline in my nginx config. Turning this off, made the form submit as expected, but no assets, if I turnedaliasback on, I got assets but the form was submitting wrong again.I changed the nginx config back to it's original:
and it magically started to work again.
I made a few edits all at the same time and then it was working. I didn't have the time to go back and analyse each different setting, had 25 other problems to fix after this one, so just moved on.