ndusek
(Nick Dusek)
October 19, 2022, 4:25pm
1
Hello,
I’m working on developing a Passenger app using Python and Flask and am trying to port the layout.erb
from the Sinatra example app to Python/Jinja2. In particular, I’m trying to understand where the url()
helper is implemented, as in e.g.:
<link rel="stylesheet" type="text/css" href="<%= url("/bootstrap-3.3.7/css/bootstrap.min.css") %>">
Is this an OOD-specific Ruby function or does it come from a different third-party Ruby library? Apologies if this is common knowledge; I am not a web developer by trade or training.
Thanks,
Nick
gbyrket
(Gerald Byrket)
October 20, 2022, 1:58pm
2
Hi Nick.
the url function is a home-grown function to generate urls specific to ondemand.
Inside the code for the dashboard are several different definitions for the url function.
grep -sr 'def url' *
app/apps/dev_router.rb: def url
app/apps/manifest.rb: def url
app/apps/ood_app.rb: def url
app/apps/sys_router.rb: def url
app/apps/usr_router.rb: def url
app/models/batch_connect/app.rb: def url
I hope this helps.
Thanks,
-gerald
ndusek
(Nick Dusek)
October 31, 2022, 6:58pm
3
Hi Gerald,
Sorry for the slow reply. Thank you, that is helpful.
Nick
No since you’re using Sinatra - that’s a sinatra function. We use Ruby on Rails a different Ruby web framework.
Looks like url
is this function.
end
# According to RFC 2616 section 14.30, "the field value consists of a
# single absolute URI"
response['Location'] = uri(uri.to_s, settings.absolute_redirects?, settings.prefixed_redirects?)
halt(*args)
end
# Generates the absolute URI for a given path in the app.
# Takes Rack routers and reverse proxies into account.
def uri(addr = nil, absolute = true, add_script_name = true)
return addr if addr =~ /\A[a-z][a-z0-9+.\-]*:/i
uri = [host = String.new]
if absolute
host << "http#{'s' if request.secure?}://"
host << if request.forwarded? || (request.port != (request.secure? ? 443 : 80))
request.host_with_port
else
request.host
end
(they alias url
to uri
)
request.host_with_port
else
request.host
end
end
uri << request.script_name.to_s if add_script_name
uri << (addr || request.path_info).to_s
File.join uri
end
alias url uri
alias to uri
# Halt processing and return the error status provided.
def error(code, body = nil)
if code.respond_to? :to_str
body = code.to_str
code = 500
end
response.body = body unless body.nil?
halt code
ndusek
(Nick Dusek)
November 1, 2022, 1:48pm
5
Thanks for the clarification! I changed this to the solution.
Nick
system
(system)
Closed
April 30, 2023, 1:49pm
6
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.