Include custom folder specific assets in ruby on rails

vipin8169

I am trying to create separate folders for keeping the assets related to backend and frontend. I planned the following folder structure: app/assets/dashboard/javascripts instead of the usual one app/assets/javascripts.

enter image description here

Backend is served via app/views/layouts/dashboard.html.erb, and includes the assets in the following way:

<%= stylesheet_link_tag 'dashboard/dashboard', params[:controller], media: 'all' %>
<%= javascript_include_tag 'dashboard/dashboard', params[:controller] %>

Front end is served via app/views/layouts/application.html.erb, and includes the assets in the following way:

<%= stylesheet_link_tag 'store/application', params[:controller], media: 'all' %>
<%= javascript_include_tag 'store/application', params[:controller] %>

I am not sure that what is the correct way to include the assets in this way, and hence getting 404 not found error for http://dashboard.localhost.com:3000/javascripts/dashboard/javascripts/dashboard.js in the console

I've also tried changing the scripts path to <%= javascript_include_tag 'store/javascripts/application', params[:controller] %>, but it doesn't work either. Also tried adding the following piece of code mentioned here to application.rb, but it didn't work either:

Dir.glob("#{Rails.root}/app/assets/**/").each do |path|
      config.assets.paths << path
end

With these settings the paths populated in the console are as follows:

[9] pry(main)> Rails.application.config.assets.paths 
=> ["/home/vipin8169/projectRoot/inmonarch_website/app/assets/images",
 "/home/vipin8169/projectRoot/xyz/app/assets/javascripts",
 "/home/vipin8169/projectRoot/xyz/app/assets/stylesheets",
 "/home/vipin8169/projectRoot/xyz/vendor/assets/javascripts",
 "/home/vipin8169/projectRoot/xyz/vendor/assets/stylesheets",
 "/home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/jquery-rails-4.1.0/vendor/assets/javascripts",
 "/home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/coffee-rails-4.1.1/lib/assets/javascripts",
 "/home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/react-rails-1.6.2/lib/assets/react-source/development-with-addons",
 "/home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/react-rails-1.6.2/lib/assets/javascripts/",
 "/home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/bootstrap-sass-3.3.6/assets/stylesheets",
 "/home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/bootstrap-sass-3.3.6/assets/javascripts",
 "/home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/bootstrap-sass-3.3.6/assets/fonts",
 "/home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/bootstrap-sass-3.3.6/assets/images"]

Is it supported in rails, altering the assets directory structure in this way?

Awais Shafqat

In your application.rb file. add this

config.assets.enabled = true

config.assets.paths << Rails.root.join("app", "assets", "dashboard")

It would add this folder under the assets path. After that

stylesheet_link_tag 'dashboard', params[:controller], media: 'all'

would work.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

rails 4 asset_pipeline : Include whole folder for vendor/assets

From Dev

rails 4 asset_pipeline : Include whole folder for vendor/assets

From Dev

Custom URL for assets folder in Jekyll

From Dev

Shopify app - how to include assets using an app-proxy with ruby on rails

From Dev

Path to private assets on Ruby on Rails

From Dev

Ruby on Rails Precompiling assets failed

From Dev

Include local assets in dist folder using webpack

From Dev

Include assets javascript coffee to view partial on rails

From Dev

Rails not precompiling images in the app/assets/images folder?

From Dev

Ruby on Rails Assets are not loading with Nitrious.io

From Dev

How assets precompile in development environment on ruby on rails?

From Dev

Ruby on Rails assets - where are files located

From Dev

Copying assets folder subdirectories to specific folder in external storage

From Dev

Precompile and include fonts in Ruby on Rails

From Dev

Rails controller specific assets for selected controllers only

From Dev

Rails controller specific assets for selected controllers only

From Dev

Custom scaffold in ruby on rails

From Dev

Custom Search in Ruby on Rails

From Dev

How to include Custom exception in Rails?

From Dev

Include a custom module on Spree and Rails

From Dev

Gradle include native libaries in folder at specific path

From Java

.gitignore exclude folder but include specific subfolder

From Dev

Include specific file from exluding folder

From Dev

Rails - Include different assets for mobile and desktop for an AngularJS app?

From Dev

How to include with rails-assets.org a package with a . in the name?

From Dev

How to set a custom font from the assets folder to the title of an Actionbar in Android?

From Dev

Ruby on Rails custom update action

From Dev

custom link_to - ruby on rails

From Dev

Set.include? for custom objects in Ruby

Related Related

  1. 1

    rails 4 asset_pipeline : Include whole folder for vendor/assets

  2. 2

    rails 4 asset_pipeline : Include whole folder for vendor/assets

  3. 3

    Custom URL for assets folder in Jekyll

  4. 4

    Shopify app - how to include assets using an app-proxy with ruby on rails

  5. 5

    Path to private assets on Ruby on Rails

  6. 6

    Ruby on Rails Precompiling assets failed

  7. 7

    Include local assets in dist folder using webpack

  8. 8

    Include assets javascript coffee to view partial on rails

  9. 9

    Rails not precompiling images in the app/assets/images folder?

  10. 10

    Ruby on Rails Assets are not loading with Nitrious.io

  11. 11

    How assets precompile in development environment on ruby on rails?

  12. 12

    Ruby on Rails assets - where are files located

  13. 13

    Copying assets folder subdirectories to specific folder in external storage

  14. 14

    Precompile and include fonts in Ruby on Rails

  15. 15

    Rails controller specific assets for selected controllers only

  16. 16

    Rails controller specific assets for selected controllers only

  17. 17

    Custom scaffold in ruby on rails

  18. 18

    Custom Search in Ruby on Rails

  19. 19

    How to include Custom exception in Rails?

  20. 20

    Include a custom module on Spree and Rails

  21. 21

    Gradle include native libaries in folder at specific path

  22. 22

    .gitignore exclude folder but include specific subfolder

  23. 23

    Include specific file from exluding folder

  24. 24

    Rails - Include different assets for mobile and desktop for an AngularJS app?

  25. 25

    How to include with rails-assets.org a package with a . in the name?

  26. 26

    How to set a custom font from the assets folder to the title of an Actionbar in Android?

  27. 27

    Ruby on Rails custom update action

  28. 28

    custom link_to - ruby on rails

  29. 29

    Set.include? for custom objects in Ruby

HotTag

Archive