简体   繁体   English

Ruby on Rails目录路径

[英]Ruby on Rails Directory Path

I need to print Ruby on Rails complete url in my application. 我需要在我的应用程序中打印Ruby on Rails完整URL。 in details 详细

with RAILS_ROOT I m getting a url like this 与RAILS_ROOT我得到这样的网址

D:/projects/rails_app/projectname/data/default.jpg D:/projects/rails_app/projectname/data/default.jpg

But for my application I need a path like this 但是对于我的应用程序,我需要这样的路径

http://localhost:3000/data/default.jpg http:// localhost:3000 / data / default.jpg

Please help me to solve this issue. 请帮我解决这个问题。 I am using Rails 2 我正在使用Rails 2

Thanks 谢谢

Today we use URI . 今天,我们使用URI Simply require the library and you will be able to parse your current dynamic and static URI any way you please. 只要require的库,这样就能够分析您的当前动态并请您静态URI的任何方式。 For example I have a function that can read URI parameters like so... 例如,我有一个可以读取URI参数的函数,例如...


#{RAILS_ROOT}/app/helpers/application_helper.rb (The literal path string of the file depicted below) #{RAILS_ROOT}/app/helpers/application_helper.rb (如下所示的文件的文字路径字符串)

def read_uri(parameter)
  require 'uri'
  @raw_uri = URI.parse(request.original_fullpath)
  @uri_params_raw = @raw_uri.query
  if @uri_params_raw =~ /\=/
    @uri_vars = @uri_params_raw.split('=')
    return @uri_vars[parameter]
  end
  return false
end

This should split all URI parameters into an array that gives the requested (numeric) "parameter". 这应该将所有URI参数拆分为一个数组,该数组提供所请求的(数字)“参数”。 I believe that simply the URI.parse(request.original_fullpath) should work for you. 我认为,简单的URI.parse(request.original_fullpath)应该适合您。 I come from using a minimum of rails 4.2.6 with this method so, I hope it works for anyone who might view this later on. 我来自使用此方法的最低轨数4.2.6,因此,我希望它对以后可能会看到此内容的任何人都有效。 Oh, and just as a disclaimer: I wasn't so wise to rails at the time of posting this. 哦,就像免责声明:发布此消息时,我不是那么明智。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM