not finding rails asset index file - ruby-on-rails-3

I have two index files in my rails assets directory
app/assets/some_feature/
index.js
app/assets/lib/my_library
index.js
if I do a
= require some_feature
it finds the some_feature/index.js file just fine
If I do a
= require lib/my_library
it will not find lib/my_library1.3/index.js
If I do a
= require lib/my_library1.3/index.js
all works well.
In otherwords for the index.js that is nested inside lib/my_library1.3 I have to explicitly name the index file to get it to load.
Is this expected? I would think I could just reference the library and away I go.
Rails 3.2

Looks like the "dot" in the name prevents rails from finding the index. Why I don't know

Related

Laravel - Bootstrap - NPM Watch is not replacing css matches, it's adding

Laravel 8 - Bootstrap 4
I have two Laravel projects. One created and running in docker, the other created and running in Vagrant/Homestead. The setups are almost the same otherwise.
However, in my vagrant/homestead project, when I use variables in my app.scss file like these:
$theme-colors: (
"blue": #007bff,
"indigo": #4B0082,
"purple": #6d388c,
"pink": #e83e8c,
);
What compiles into my app.css file, is duplicated for the items above, like this:
:root {
--blue: #3490dc;
--indigo: #6574cd;
--purple: #9561e2;
--pink: #f66d9b;
--blue: #007bff;
--indigo: #4B0082;
--purple: #6d388c;
--pink: #e83e8c;
}
With my colors lower in the file. The end result is the same, as the lower variables take precedence, and they aren't double processed into the classes where they are included either.
It seems something is wrong, as this does not happen in my project on the docker install. Is it possible that the mixin (or...) rules changed to now include the duplicates? Hard to guess that is true.
I don't believe docker or vagrant has anything to do with this, I'm just using those specifics to keep clear which is which.
Any ideas? Thanks.

Rails 3 Routes - prepend all url paths with set string

I've been asked to change the routes on a Rails project such that the routes will only respond to requests where the app name (or other arbitrary string) is the first string after the domain name, e.g.
www.thething.com/appname/users/sign_in instead of www.thething.com/users/sign_in
www.thething.com/appname instead of www.thething.com
www.thething.com/appname/search instead of www.thething.com/search
I've suggested using a subdomain appname.thething.com instead, but the client is quite specific about wanting the URL in the above format.
www.thething.com will be a splash page which will contain a link to www.thething.com/appname, with the intention of adding additional apps/pages in future with new folder names.
Is there an easy way of modifying the routes file so that all routes will get the .../appname prepended to all resources and routes, while being after the domain?
One option is wrap all existing routes in: namespace :appname do ... end, like so:
# config/routes.rb
Appname::Application.routes.draw do
namespace :appname do
# existing routes go here
end
end
I'm not sure if this is the most elegant solution, but it will prepend /appname to all the routes.

tradeoff routes and views rails 3

here it's routes.db
resources :licenses do
resources :sublicenses do
resources :time_licenses
end
end
Then there is a client application that calls time_licenses_controller for creating new time_licenses, the controller responds with a json file, but i don't need to show any view.
Somewhere else instead i need to show to the client an index file including all time_licenses for every sublicense.
That's the path
license/:id/sublilicense/:id/time_lincenses
Now i have a problem with the routes. When i call the create on time_licenses_controller i get this error:
No route matches "/time_licenses.js"
that i can solve changing the routes.db file like this
resources :time_licenses
resources :licenses do
resources :sublicenses
end
but in that case i get the same error linking the index view.
What do you suggest me? Do i have to create two different controllers?
Since you are using nested resources, you will always need to specify license and sublicense while specifying the path to timelicense.
Your path helpers will be:
license_sublicense_timelicense_path(#license, #sublicense, #timelicense) and so on
You can get the path names for the timelicense by
rake routes
Refer rails guides - nested resources for any doubts.

How to allow access to group of generated sub trees in web.config using RegEx?

Here is what I need to do:
In my CodeIgniter application, I have a folder named "modules", and each module contains (among others) a folder named assets, which contains all the resources that need to be available from the browser.
The file structure is in this format:
modules
MyModule
assets
views
etc...
The MyModule folder is dynamic, so I need to add a rule that does not rewrite the paths like
/modules/ANY MATCH/assets
but I can't figure out the proper Regular Expression...
My current pattern is the following:
^(index\.php|robots\.txt|libs|themes|app/modules/^.$/assets|sitemap.xml)
but the ^.$ obviously doesn't work... I'm a complete RegEx noob :/
Any help would be appreciated. Thanks for your time!
I think you want
^(index\.php|robots\.txt|libs|themes|app/modules/.*/assets|sitemap\.xml)
or better, if ANY MATCH is always a single folder only:
^(index\.php|robots\.txt|libs|themes|app/modules/[^/]*/assets|sitemap\.xml)

Rails: is there an Engine.root?

Rails.root returns a Path object specifying the root of a Rails project.
Is there an equivilent for Rails engines? Like Engine.root? If not, how else could I build up a path from the root of my Rails engine?
Lets say your engine file is set up like this:
module MyEngine
class Engine < Rails::Engine
#......
end
end
You can call root on the Engine class like this:
MyEngine::Engine.root
John's answer is right, but I'd clean that up a little bit like this:
When you mount your engine within your routes file add an alias first.
mount YourEngineNameHere::Engine => '/optional_namespace', as: 'your_engine_name'
Then do your_engine_name.root_url