Here is my simple app:
class Blog < E
map '/'
# actions goes here
end
app = EApp.new do
# assets_url '/', true
mount Blog
end
app.run server: :Thin, Port: 6040
It works well until i uncomment assets_url '/', true.
If i do so, all my routes returning 404 and only routes pointing to files in assets folder works.
Any ideas?
Everything looks correct except assets URL.
You are mounting your app and assets server on same URL - /
Assets server has precedence, thus your app routes wont work.
Simply mount your assets on a corresponding URL, /assets, /static, /etc
app = EApp.new do
assets_url '/assets', true
mount Blog
end
UPDATE: as of version 0.4.6, assets server moved to Espresso Lungo
So install el gem - $ gem in el - or add it to Gemfile - gem "el"
Related
I am facing asset loading issue in Rails 5 application deployed on Heroku.
App Configuration is,
ruby => ‘2.3.1’
rails => '~> 5.0.1'
When image is stored on path,
app/assets/home/image1.jpg
I am accessing it in view as,
= image_tag('/assets/home/image1.jpg’)
which is working properly in Development ENV, but not in Production ENV.
As per Heroku log,
ActionController::RoutingError (No route matches [GET]
"/assets/home/image1.jpg")
If I am moving image directly to
app/assets/image1.jpg
then its working on Production ENV.
Please guide about it.
Thanks
It looks like you assets are not compile on heroku.
Follow below code:
config/environments/production.rb
config.assets.compile = true
then run commands:
RAILS_ENV=production rake assets:precompile
then push all compiled files with menifest file to heroku.
I have currently my octopress blog up and running on my digital ocean droplet and everything works fine. But it is in the root folder of the droplet and I want to move it to a blog folder. Is that just moving all content to that subfolder, or is there more work to do to get this done to be aware of?
According to the Octopress documentation, if you are deploying in a subdirectory you'll need to update the following files:
_config.yml
config.rb
Rakefile
If you're deploying to a subdirectory on your site, or if you're using
Github's project pages, make sure you set up your urls correctly in
your configs. You can do this almost automatically:
rake set_root_dir[your/path]
# To go back to publishing to the document root
rake set_root_dir[/] Then update your _config.yml and Rakefile as follows:
# _config.yml
url: http://yoursite.com/your/path
# Rakefile (if deploying with rsync)
document_root = "~/yoursite.com/your/path"
To manually configure deployment to a subdirectory, you'll change _config.yml, > config.rb and Rakefile. Here's an example for deploying a site to the /awesome
subdirectory:
# _config.yml
destination: public/awesome
url: http://example.com/awesome
subscribe_rss: /awesome/atom.xml
root: /awesome
# config.rb - for Compass & Sass
http_path = "/awesome"
http_images_path = "/awesome/images"
http_fonts_path = "/awesome/fonts"
css_dir = "public/awesome/stylesheets"
# Rakefile
public_dir = "public/awesome"
# If deploying with rsync, update your Rakefile path
document_root = "~/yoursite.com/awesome"
source: http://octopress.org/docs/deploying/subdir/
Say I have a config.ru like:
map '/foo' do
run MyApp
end
and a Sinatra app like:
class MyApp < Sinatra::Base
use Rack::Session::File, key: 'rack.session', domain: 'my.domain.com', path: '/foo', expire_after: 86400 * 14, secret: 'mysecret'
end
How can I make MyApp agnostic to which request directory (/foo in this case) is used to access it? I have found that request.script_name contains this directory, but I cannot use it for the path: parameter of the use Rack::Session::File statement since it is not defined yet when starting the app from passenger, but only when requests are sent to the application later.
Unfortunately it's impossible even with dirty hacks.
So I suppose it's possible to do via two different ways:
External configuration file e.g. routes.yml (config.ru uses it for
map statement, application to discover such prefix in url);
Environment variable (I've chosen this because it's easy to configure on Heroku.
Working on rails, images are not visible and giving error.
Started GET "/assets/home.png" for 127.0.0.1 at 2012-06-19 12:23:24 +0530
Served asset /home.png - 404 Not Found (24ms)
ActionController::RoutingError (No route matches [GET] "/assets/home.png"):
I have used command
rake assets:precompile
production.rb
config.assets.compress = true
config.assets.compile = false
application.rb
config.assets.enabled = true
config.assets.version = '1.0'
Thanks for any help!
Actually you cannot reference your image with /assets/home.png path.
It will work in development mode, but in production all of your assets have a fingerprint in their filename (read this http://guides.rubyonrails.org/asset_pipeline.html#what-is-fingerprinting-and-why-should-i-care-questionmark)
That's why, in assets-pipeline enabled applications you need to reference all of your assets using helper methods. Read this doc to learn about the different helpers available in Ruby, JS and Sass files: http://guides.rubyonrails.org/asset_pipeline.html#coding-links-to-assets
The lack of a fingerprint in the file request suggests that you are running this in development. I am also going to guess that this is an app upgraded from an older version of Rails.
Any images need to be in the folder /assets/images for the pipeline to work.
Also, you do not need to precompile when in development mode.
Delete the public/assets folder, delete the folder tmp/cache/assets, and restart your server.
If this images are in the correct location, it should work.
My development rails env can't read image files. I added config.serve_static_assets = false in development.rb. But that didn't resolve. What else I need to change here?
Started GET "/assets/images/ui-icons_888888_256x240.png" for 10.10.10.10 at 2012-05-12 22:02:32 -0400
Served asset /images/ui-icons_888888_256x240.png - 404 Not Found (45ms)
ActionController::RoutingError (No route matches [GET] "/assets/images/ui-icons_888888_256x240.png"):
Make sure that your config/application.rb is configured to use the asset pipeline.
config.assets.enabled = true
Also, make sure your file is in the right place
/app/assets/images/ui-icons_888888_256x240.png
And now that you mention that you're using jQuery UI, you need to make sure that the asset can be found. Typically, you'd want them to be found at:
/vendor/assets/images/*
How you make that happen is up to you. You could copy all the images from wherever they are in the jQuery UI download to that directory.