1

I would like to exclude a specific folder from assets/javascripts in my application.html.haml

The folder that I do not want to be included in my layout is mobile folder

Here's my layout:

%html(lang="en")
  %head
    %meta(charset="utf-8")
    %meta(http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1")
    %meta(name="viewport" content="width=device-width, initial-scale=1.0")
    %title= content_for?(:title) ? yield(:title) : @user.name ? 'Niche | ' + @user.name : 'Niche'
    = csrf_meta_tags
    = analytics_init if Rails.env.production?
    / Le HTML5 shim, for IE6-8 support of HTML elements
    /[if lt IE 9]
      = javascript_include_tag "//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.6.1/html5shiv.js"
    = stylesheet_link_tag "application", :media => "all"

  %body#profile

    %section.persist-area
      %header.global.profile
        %div.container
          %a.brand.pull-left{ :href => root_path }
            .logo-niche


          %nav.pull-right
            = render 'layouts/menu'

      .container-fluid#main
        = yield :profile

      /
        Javascripts
        \==================================================
      / Placed at the end of the document so the pages load faster
      = javascript_include_tag "application"
      = yield :javascript

In this snippet, I am getting all JS:

= javascript_include_tag "application"

But I want to get all JS except the folder named mobile

I tried the following workaround but did not work:

= javascript_include_tag "application", except: "mobile"

Sorry that was just a wild guess. There's no javascript_exclude_tag too as per the docs.

Any ideas? Thanks.

PS: I have a different layout for mobile, so that's why I really want to exclude that folder in desktop view. It's conflicting a lot of conflicts in my desktop view.

1 Answer 1

1

Change in application.js

//= require_tree

to

//= require_directory .

or

//= require_tree ./useful

So that, app/assets/javascripts/* files will be included and app/assets/javascripts/mobile/* wont be included.

Sign up to request clarification or add additional context in comments.

3 Comments

So then... other folders will not be required (e.g. I also have a lib folder)? Is there any way to exclude just one folder? Thanks btw for the reply.
I would do "//= require_tree ./useful" and under useful, all folders and files that I require will be kept. "/mobile" will be excluded. Here I assume 2 folders in my "app/assets/javascripts", "mobile and useful"
Thanks for the answer but I used stub as well. Just for additional info, if others encounter this problem: stackoverflow.com/questions/7602393/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.