1


I'm trying to combine Padrino with Sinatra-Assetpack, without success.

This is my Gemfile:

source :rubygems

gem 'rake'
gem 'sinatra-flash', :require => 'sinatra/flash'

# Component requirements
gem 'haml'

# Assets requirements
gem 'sinatra-assetpack', :require => 'sinatra/assetpack'

# Test requirements

# Padrino Stable Gem
gem 'padrino', '0.10.6'

in my app/app.rb file I set:

require 'sinatra/assetpack'

class Coffee < Padrino::Application
  register Padrino::Rendering
  register Padrino::Mailer
  register Padrino::Helpers

  register Sinatra::AssetPack

  assets {
    serve '/js',  from: '/app/assets/javascripts'
    serve '/css', from: '/app/assets/stylesheets'

    css :main, ['/css/main.css']
    js  :application, ['/js/application.js']
  }

  enable :sessions

end

my javascript files are in /app/assets/javascripts and css files in /app/assets/stylesheets, but Padrino respond with a 404 for both /css/main.css and /js/application.js

Any ideas?

Thanks

phillbaker
  • 1,518
  • 11
  • 22
  • Thats very weird... I started a 50pt bounty on this question, and it was never awarded by the question creator, but I did not get the 50 pts back.. whats up with that? – Bill Dami May 08 '12 at 19:46

1 Answers1

1

Figured out the issue, in my application anyway, but from the looks of your app.rb code it's probably the same for you;

Assetpack serves files from the directories you specify in your serve calls, relative to your application's root. In padrino, the application root is yourapplication/app, so if you tell assetpack to serve css from /app/assets/stylesheets for instance, its really looking for the files in yourapplication/app/app/assets/stylesheets.

The second part of the problem was that in the AssetPack docs, it shows the code

set :root, File.dirname(__FILE__)

before the register Sinatra::AssetPack line, which I assume is setting the application's root directory properly so that AssetPack will look in the root application directory instead of app. However, even If I modified that call to set to go up one directory from the app.rb file (since it sits in the app dir in Padrino), it didn't seem to have any effect on AssetPack.

In short, modifying the from: paths in the `serve' calls to be relative to your app directory should fix the problem. In your case, they should be:

serve '/js',  from: '/assets/javascripts'
serve '/css', from: '/assets/stylesheets'
Bill Dami
  • 3,205
  • 5
  • 51
  • 70