Search code examples
htmlruby-on-railsrubyasset-pipelineassets

How can use a custom folder asset using namespace routes?


I'm trying to use a template created and apply it into a ruby on rails project without adding assets or use ruby on rails procedures.

Is it possible to use a custom folder on namespace routes?

When I execute the project doesn't works without using namespaces but when i use a resources it works perfect.

Examples:

user_management/users/index.html.erb works ok.
user_management/users/new.html.erb  doesn't load assets.
user_management/users/new.html.erb  doesn't load assets.
users/index.html.erb works ok.
users/ new.html.erb works ok.
users/edit.html.erb works ok.

Github project code:

 https://github.com/sayayingod/app_sow

application.rb

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

Routes.rb

namespace :user_management do
  resources :users
end    

resources :users 
#Root Configuration
root 'user_management/users#new'

user_management/users/new.html

users/new.html.erb

enter image description here


Solution

  • You have relative paths like this everywhere: <script src="../assets/js/app.min.js"></script>, use absolute paths instead: <script src="/assets/js/app.min.js"></script>.

    Also, use rails helpers like javascript_include_tag, stylesheet_link_tag, image_tag, etc, don't hardcode the tags, you'll have less headhaches.