Comments (4)
hey @vtamara ๐๐ป I remember responding to you over in #49688. In my PR, I think this note under "Other Information" is very relevant:
The existing tests imply that the proper way to mount Rails with a relative url root is to customize
config.ru
with amap
directive, which produces theSCRIPT_NAME
which Rails handles implicitly and correctly for the main Application and Mounted Engines.The
config.relative_url_root
seems to be intended only for generating paths outside of a request/controller/view (e.g. when using*.routes.url_helpers.some_path
).
In reference to my first paragraph, I think that your example application is set up confusingly and incorrectly (example: root
is not the same as as: :root
, which you have nested below the root of the Rails Rack App); at minimum, it omits the set up of Rack and/or any path-rewriting webservers (nginx, apache, etc). The latter is why your tests are failing: you have not changed the test harness's Rack mount point for the Rails Rack App to account for the config.relative_url_root
.
In reference to my second paragraph, I think you are violating the purpose of config.relative_url_root
by using include Rails.application.routes.url_help
in your Controllers; the Controllers' existing URL helpers should be correct.
Also, I did say I would do a pass at the documentation. I have not yet done that ๐
from rails.
Hi @bensheldon , thanks for the answer.
I started this new bug report because in our discussion at #49688, at the end I described the problem that I present here without any answer from you.
In the test case I presented here, I understand the confussion of as :homoot
, it is possible to change it by as :index
, also root_path
should be replaced by index_path
, but the result is the same.
Also it is possible to remove include Rails.application.routes.url_helpers
from the controller but the result is the same.
Could you please tell me how to change in the test case the "test harness's Rack mount point for the Rails Rack App to account for the config.relative_url_root
"
Now some good news, following your suggestion in the simple example application that I
used in #49688 i.e. https://gitlab.com:vtamara/app49688 I changed config/routes.ru
to be:
require_relative "config/environment"
map "/a" do
run Rails.application
Rails.application.load_server
end
and removed scope "a/"
from config/routes.rb
and it worked.
After I tried the same change in the example application of this engine https://gitlab.com/pasosdeJesus/msip whose default mount point is /msip
To make work the assets in develpoment mode I had to create a link from public/msip/assets
to public/assets
and it worked partially.
I say partially because in some situations the route helpers of the engine generate wrong paths, for example the main menu (test/dummy/app/views/layout/application.html.erb) has msip.orgsociales_path
and in the home page it becomes /msip/orgsociales
but from the index view of Msip::OrgsocialesController
it becomes /orgsociales
.
from rails.
Sorry to have missed a follow-up on #9688 ๐
Could you please tell me how to change in the test case the "test harness's Rack mount point for the Rails Rack App to account for the config.relative_url_root"
I don't know for sure ๐ The metho used for simulating it in the tests was setting a SCRIPT_NAME=
parameter with the relative root:
rails/railties/test/railties/engine_test.rb
Line 1680 in 4c0ecea
Or in other words:
get("/posts/1", {}, { "SCRIPT_NAME" => "/foo" })
# is equivalent to the absolute path /foo/posts/1
# when using this rack configuration:
map "/foo" do
run Rails.application
end
(though that should work regardless of config.relative_url_root
)
I think I'm still a little unclear specifically on why you're using config.relative_url_root
. That's only necessary if you're hosting the Rails application at a different path than the /
. In your examples, it seems like you're still hosting the Rails application at /
and then adding additional routes.
I say partially because in some situations the route helpers of the engine generate wrong paths, for example the main menu (test/dummy/app/views/layout/application.html.erb) has msip.orgsociales_path and in the home page it becomes /msip/orgsociales but from the index view of Msip::OrgsocialesController it becomes /orgsociales.
Can you show me the example of that? I didn't see an index.html
template for that.
from rails.
Thank you @bensheldon
Or in other words:
get("/posts/1", {}, { "SCRIPT_NAME" => "/foo" })
When I try this, I get the error:
ArgumentError: wrong number of arguments (given 3, expected 1)
If I try with:
get("/posts/1", params: {}, headers: { "SCRIPT_NAME" => "/foo" })
It doesnยดt present error but it doesnยดt work.
Any hint?
Can you show me the example of that? I didn't see an
index.html
template for that.
I could solve (instead of assigning config.relative_url_root
in a file at config/initializers/
it should be assigned in config/application.rb
).
Thank you.
from rails.
Related Issues (20)
- [Rails 7.1.3] async_find_by_sql needs promise.value.value ?! HOT 1
- allow_browser may prevent your site from being crawled HOT 2
- Add the ability to configure minimum number of active connections for connection pool
- jemalloc Dockerfile configuration may be problematic across architectures HOT 1
- Trilogy:EOFError cannot be recovered on ActiveRecord 7.1 HOT 1
- Rails error reporter doesn't report exceptions in production HOT 5
- Sidekiq ActiveJob adapter resets provider_job_id on with retry_job HOT 3
- Passing an array to the `model` parameter of `form_with` does not work with singular, unpersisted resources HOT 1
- Read the Ruby Version in Gemfile Instead of Hardcoding the Version HOT 2
- `render "fizz"` and `render partial: "fizz"` behave differently when given a block HOT 2
- Pure ruby view templates, pages and components HOT 1
- `FileNotFoundError` in `AnalyzeJob` HOT 1
- nested_attributes_for :limit does not account for records marked for deletion
- no implicit conversion of String into Integer (TypeError) @env[name] HOT 2
- Relation `#distinct` doesn't raise an error for invalid arguments HOT 2
- ActiveModel::Dirty is broken in after_commit
- Blocked hosts: site.com To allow requests to these hosts, make sure they are valid hostnames (containing only numbers, letters, dashes and dots), then add the following to your environment configuration: config.hosts << "site.com" For more details view: the Host Authorization guide HOT 2
- GlobalID::Locator.locate_signed cannot find SGIDs created in a Rails 6.1 app HOT 5
- New find_or_create_by behavior in Rails 7.1 can introduce subtransactions in PostgreSQL HOT 5
- Invalid route POST request results in key space error 500 instead of 404 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rails.