V
V
Vayladion Gognazdiak2018-03-27 14:42:00
Ruby on Rails
Vayladion Gognazdiak, 2018-03-27 14:42:00

Is it possible to make a certain kind of hyperlink in rails?

Good day!
ENV: Rails 5.1.4
There is a service (2-3 pages). All resources (pictures, fonts, etc.) are in assets.
you
<%= image_tag "logo.png" %>
will give us

<img src="/assets/logo-b99dbe0ace3298702942689991a789129fcfb13538ad3216f6eee9c805c5a3af.png" alt="Logo">

All of a sudden it was required that links to resources look like:
начинались с точки
<img src="./assets/logo-b99dbe0ace3298702942689991a789129fcfb13538ad3216f6eee9c805c5a3af.png" alt="Logo">

or
были без первого /
<img src="assets/logo-b99dbe0ace3298702942689991a789129fcfb13538ad3216f6eee9c805c5a3af.png" alt="Logo">

This is necessary for proxying through nginx.
On my puma side + standard nginx config
On the remote side, something like:
location /fff/bbb/ccccc/ {
proxy_pass http://putin.ru;
}

I'll be honest - it somehow confused me and plunged me into despondency.
Experiments with assets.prefix and relative_url_root didn't work.
In this regard, I have 2 questions?
1. Is this even possible?
2. If possible, how can this be implemented in this case?
PS: Thanks in advance for your reply. From me, as usual - tons of respect and respect!
PPS: I suspect that this is still done using nginx

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
ark_m, 2018-04-05
@etspring

I think the easiest option would be to use asset_path with interpolation:

<img src="<%= ".#{asset_path 'logo.png'}" %>" alt="Logo">

R
Roman Mirilaczvili, 2018-03-27
@2ord

The URLs themselves are generated in RoR, and nginx only gives content, nothing more.
edgeguides.rubyonrails.org/asset_pipeline.html#cha...

The public path that Sprockets uses by default is /assets.
This can be changed to something else:
You need to fix the config/environments/production.rb file
https://stackoverflow.com/a/37918186
Alternatively, you can generally store all the static on a separate CDN server:
DNS:
cloudfront (.mysite.com) CNAME --> mysite.cloudfront.com

V
Vayladion Gognazdiak, 2018-03-27
@etspring

I tried it, you won’t get links like ./assets/ through this
until you just made a monkeypatch for helpers, but this is a hard option too

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question