Code Monkey home page Code Monkey logo

Comments (4)

bensheldon avatar bensheldon commented on May 28, 2024

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 a map directive, which produces the SCRIPT_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.

vtamara avatar vtamara commented on May 28, 2024

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.

bensheldon avatar bensheldon commented on May 28, 2024

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:

get("/bukkits/bukkit", {}, { "SCRIPT_NAME" => "/foo" })

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.

vtamara avatar vtamara commented on May 28, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.