Skip to content

rails 3.1 style asset url resolutions #184

Open

Description

@bhavinkamani

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.

Activity

  1. bhavinkamani commented on Jun 3, 2011

    @bhavinkamani
    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.

  2. serek commented on Jun 15, 2011

    @serek

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

  3. bhavinkamani commented on Jun 15, 2011

    @bhavinkamani
    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?

  4. jashkenas commented on Jun 15, 2011

    @jashkenas
    Member

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

  5. bhavinkamani commented on Jun 15, 2011

    @bhavinkamani
    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 %>
    
  6. jashkenas commented on Jun 15, 2011

    @jashkenas
    Member

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

  7. vandrijevik commented on Jun 15, 2011

    @vandrijevik
    Contributor

    Whoops, my bad! Deleted my misleading comment.

  8. bhavinkamani commented on Jun 15, 2011

    @bhavinkamani
    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?

  9. jashkenas commented on Jun 15, 2011

    @jashkenas
    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.

  10. agibralter commented on Jun 16, 2011

    @agibralter
    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.

  11. bhavinkamani commented on Jun 16, 2011

    @bhavinkamani
    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?

  12. fluxsaas commented on Sep 19, 2011

    @fluxsaas

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions