Как я получаю базовый URL (например, http://localhost:3000) моего приложения для направляющих?

Если тип известен вызывающей стороне, существует лучший, более быстрый путь, чем использование Активатора. CreateInstance: можно вместо этого использовать универсальное ограничение на метод, который указывает, что имеет конструктора без параметров по умолчанию.

Выполнение его этот путь безопасен с точки зрения типов и не требует отражения.

T CreateType<T>() where T : new()
{
   return new T();
}
9
задан Wayne Molina 2 October 2009 в 15:37
поделиться

2 ответа

asset.url returns the URL to the file. This is usually /system/classname/xx/xx/style/filename.ext. You'd put this in an image_tag.

You want asset.path. It returns the full path to the file, which will usually be something like /home/username/railsapp/public/system/classname/xx/xx/style/filename.ext

HTH.

4
ответ дан 4 December 2019 в 07:35
поделиться

Typically root_url should provide this.

File.read is expecting a file path, not a url though. If you are generating the images, you should call the image generating code and return the bytes of the generated image instead of calling File.read(…)

20
ответ дан 4 December 2019 в 07:35
поделиться
Другие вопросы по тегам:

Похожие вопросы: