Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rails 3.1 style asset url resolutions #184

Open
bhavinkamani opened this issue Jun 3, 2011 · 12 comments
Open

rails 3.1 style asset url resolutions #184

bhavinkamani opened this issue Jun 3, 2011 · 12 comments

Comments

@bhavinkamani
Copy link

I am experimenting with rails 3.1.

Rails is resolving assets url as assets/.js. It maps this to app/assets/jaavscripts/.js and vendor/assets/javascripts/*.js. app files gets priortiy then the vendor files.

I love jammit and would like to know if there is a way to enter assets/*.js url instead of explicit vendor or app url relative to root path in assets.yml file.

Please pardon my ignorance if something like this already exist and I am not aware of the same.

@bhavinkamani
Copy link
Author

After little more investigation, I am not able to make jammit work with rails 3.1 vendor assets. on giving vendor/assets/javascripts/*.js, it gives same path in my html.

   <script src="/vendor/assets/javascripts/elastic.js" type="text/javascript"></script>

I have a hunch that I am missing something silly.

@serek
Copy link

serek commented Jun 15, 2011

Ok, but there needs to be a way of running Jammit with rails 3.1 ?

@bhavinkamani
Copy link
Author

I agree with Serek. After trying out sprockets, I feel jammit is far more intuitive. Specifically, I like the way jammit manages all assets under one roof (assets.yml) and asset extensions such as template etc. I certainly miss jammit big time in rails 3.1. Also, one should have option to choose asset pipeline engine. Isn't that a fundamental rails philosophy?

@jashkenas
Copy link
Member

Jammit should work fine with Rails 3.1. Just use it as you would normally.

@bhavinkamani
Copy link
Author

I tried to use it. I am stuck at urls. How should I refer assets within assets.yml. Here's my assets.yml file. I have a simple test.js under assets/javascripts folder. I dont see the ref of test.js in the html output.

config/assets.yml

compress_assets: off

javascripts:
  workspace:
    - assets/javascripts/test.js

app/views/layoutsapplication.html.erb

  <%= include_javascripts :workspace %>

@jashkenas
Copy link
Member

You wouldn't put JavaScripts in "assets" -- you'd leave them in "public", as before.

@vandrijevik
Copy link
Contributor

Whoops, my bad! Deleted my misleading comment.

@bhavinkamani
Copy link
Author

Thanks a lot Jeremy... That works fine.

Is there a plan to allow reference to assets placed under assets/ folder. Also would one has to fall back on barista for coffeescript and compass for sass or can I use assets pipelining provided by tilt/sprockets?

@jashkenas
Copy link
Member

No, there are no plans to allow assets to be placed under the assets folder -- they need to be somewhere publicly accessible by the web server. "public" is a great place for that. I don't know about what level of sprockets integration you'll be able to get -- you'll have to ask the sprockets folks about that.

@agibralter
Copy link
Contributor

@bhavinkamani -- I've always had my assets in app/javascripts and app/stylesheets. It's actually quite easy to use jammit with this set up. All you need to do is symlink public/app/javascripts => app/javascripts. I have a hook in my config/environments/development.rb to do it automatically:

# Symlink javascripts and stylesheets on the fly.
config.after_initialize do
  if !File.exists?(File.join(Rails.root, 'public', 'app'))
    Rails.logger.info "Linking from public/ to app/javascripts and app/stylesheets for Jammit's helpers."
    `mkdir -p #{Rails.root}/public/app`
    `ln -s #{Rails.root}/app/javascripts #{Rails.root}/public/app/javascripts`
    `ln -s #{Rails.root}/app/stylesheets #{Rails.root}/public/app/stylesheets`
  end
end

This way, in development when the assets are not packaged, the URLs work.

@bhavinkamani
Copy link
Author

Thanks @agibralter for your reply. Thats a neat approach.

I liked the way tilt takes care of abstracting template engines. Similarly I like the way jammit takes care of asset packaging through one config file. Right now, it appears to me that if I want to use tilt I have to use sprockets or I have to use jammit with barista, compass and other separate gems for each templates. I would have liked to disable sprockets and enable jammit integrated with tilt. Not sure if there is already a way and I am missing something?

@fluxsaas
Copy link

you could add your folder to the assets pipeline path:

config.assets.paths << "#{Rails.root}/public/packages"

i have my .js packed there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants