Add a two different asset path in Rails 3.2 - ruby-on-rails-3

I like to use two different assets folder in my rails 3 application. I like to serve from app/assets/ and also from public/template/style1.
- app
- assets
- javascripts
- stylesheets
- **styles.css**
- images
- controllers
- models
- ----
- public
- template
- style1
- js
- css
- **theme.css**
- img
Layout file
<%= stylesheet_link_tag "styles", :media => 'screen' %>
In the same page used iframe like to use styles from public/template/style1/css/theme.css
<link href="/template/style1/css/theme.css" media="screen" rel="stylesheet" type="text/css" />
In production.rb added
config.assets.precompile += %w(styles.css)
config.assets.paths << "#{Rails.root}/public/template/style1/css"
config.assets.precompile += %w(theme.css)
I run rake assets:precompile and in browser no changes occurred. Please help me to resolve.

I think your reference to the theme.css file is not right . If you state in your production.rb adding the path "#{Rails.root}/public/template/style1/css" , you should refer to the contents in it simply like this :
<link href="theme.css" media="screen" rel="stylesheet" type="text/css" />
You can consider to stick to the "convention" about the asset-pipeline : place your assets in the assets directories .
One more slight detail: if you would like to make an asset resource to be managed by asset-pipeline , you just state this in application.css file , like this :
*= require theme

Related

vue project not working when change the base url in index.html file to my website url

This is my index.html file
when I change the base url to my website domain "https://new.weservio.com/" this error appears
Uncaught TypeError: Failed to resolve module specifier "vue". Relative references must start with either "/", "./", or "../". when I try to import vue according to this solution https://microeducate.tech/importing-a-package-in-es6-failed-to-resolve-module-specifier-vue/ .other modules can't be resolved too.
<html lang='en'>
<head>
<meta charset='UTF-8' />
<link href='images/logo.png' rel='icon' />
<meta content='width=device-width, initial-scale=1.0' name='viewport' />
<link href='https://fonts.googleapis.com' rel='preconnect'>
<link crossorigin href='https://fonts.gstatic.com' rel='preconnect'>
<link href='https://fonts.googleapis.com/css2?family=Poppins:wght#300;400;500;700;900&family=Tajawal:wght#300;400;500;700;900&display=swap'
rel='stylesheet'>
<link href=' https://cdnjs.cloudflare.com/ajax/libs/vue/3.0.0-beta.14/vue.esm-browser.js' >
<title></title>
<!--
EDIT THE FOLLOWING CODE INSIDE THE BASE TAG
'http://localhost:3000/' ==> 'REPLACE IT WITH YOUR BASE URL'
-->
<base href='https://new.weservio.com/'>
</head>
<body class='rtl:font-tajawal font-poppins overflow-x-hidden'>
<div id='app'></div>
notice: when I leave the url as "http://localhost:3000/" and run the project locally with npm run dev .The website is working fine.
notice: This site was working correctly before on same domain url ,but I was tring to use ftp-simple extention on vs code to load automaticllay after save to server from my working directory .then the website is not working anymore .I don't know if this related.

The relative file path suggests a different folder structure?

I have the below folder/file structure:
bmi-calculator > public > styles.css
bmi-calculator > views > index.ejs
bmi-calculator > bmi-calculator.js
In my index.ejs file, I have the following lines to link the css file and the js script:
<link rel="stylesheet" href="../public/styles.css">
<script src="../bmi-calculator.js" async defer></script>
However, the css styles sheet isn't linking correctly (the JS file does), but when it is changed to this it links:
<link rel="stylesheet" href="styles.css">
Futhermore, when I change the script to:
<script src="bmi-calculator.js" async defer></script>
My js file continues to link up correctly. However, the above would suggest the following folder structure:
bmi-calculator > views > index.ejs
bmi-calculator > views > bmi-calculator.js
bmi-calculator > views > styles.css
Also, I'm not sure if this changes anything, but in my bmi-calculator.js file I have app.use(express.static('public')); included in as well and I am running the script by using nodemon bmi-calculator.js.
I've read about relative file paths, but this isn't working as I would expect! Why isn't this working as it should?
The express.static sets your context for static files to the public directory. So in your static files, the path to be defined is relative to that context. So you'll be able to access anything in the public directory without doing:
../public/abc.css

asset() function in twig gives an NotFoundHttpException "No route found for "GET /favicon.ico"

I have just installed a new Symfony project (I use xampp). When I started the application the favicon on the url tab wasn't showing, i opened the source code and opend the icon from there, but I got the error message I writed in the title.
In the code the link is presented as:
<link rel="icon" type="image/x-icon" href="{{ asset('favicon.ico') }}" />
and in the source code it was like
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
What is the problem, am I missing something ?
Thanks
you should put the file in the web folder
the asset function target a folder web by default.
http://symfony.com/doc/current/best_practices/web-assets.html

ASP.NET MVC 4 - Add Bundle from Controller?

I have some pages on my site that use certain CSS and JS resources - but they are the only page(s) to use that css or js file - so I don't want to include that CSS and JS reference in every page. Rather than modify each View to reference the CSS/JS it needs, I thought I could create a bundle in the Controller and add it to the Bundles that are already registered, and then it would be included in the bundle references, but this does not appear to be possible, or maybe I'm just going about it the wrong way.
In my Controller for a registration page for example, I thought I could write this:
Bundle styleBundle = new Bundle("~/bundles/registrationStyleBundle");
styleBundle.Include("~/Content/Themes/Default/registration.css");
BundleTable.Bundles.Add(styleBundle);
And then have this in my /Views/Shared/_Layout.cshtml:
#foreach(Bundle b in BundleTable.Bundles)
{
if (b is StyleBundle)
{
<link href="#BundleTable.Bundles.ResolveBundleUrl(b.Path)" rel="stylesheet" type="text/css" />
}
else if (b is ScriptBundle)
{
<script src="#BundleTable.Bundles.ResolveBundleUrl(b.Path)" type="text/javascript"></script>
}
}
But this does not work - the only bundles to get rendered to my page end up being the ones I specified in RegisterBundles (in /App_Start/BundleConfig.cs)
Any idea how to achieve this kind of "dynamic" or "runtime" bundling?
EDIT: Following Jasen's advice, what I ended up doing was taking the bundle creation/registration code out of the controller and adding it to RegisterBundles() in /App_Start/BundleConfig.cs. This way, the bundle is already available and the contents get minified. So:
bundles.Add(
new StyleBundle("~/bundles/registrationStyleBundle")
.Include("~/Content/Themes/default/registration.css"));
Then, in my view, I added this:
#section viewStyles{
<link href="#BundleTable.Bundles.ResolveBundleUrl("~/bundles/registrationStyleBundle")." rel="stylesheet" type="text/css" />
}
Then, in /Views/Shared/_Layout.cshtml, I added this:
#RenderSection("viewStyles", required: false)
Use the #section Scripts { } block to conditionally add bundles.
_Layout.cshtml
<body>
...
#RenderSection("Scripts", required: false)
</body>
FooView.cshtml
#section Scripts {
#Scripts.Render("~/bundles/foo")
}
KungFooView.cshtml
#section Scripts {
#Scripts.Render("~/bundles/kungfoo")
}
In my BundleConfig I typically group resources
bundles.Add(new ScriptBundle("~/bundles/Areas/Admin/js").Include(...);
bundles.Add(new StyleBundle("~/bundles/Areas/Admin/css").Include(...);
bundles.Add(new ScriptBundle("~/bundles/Areas/Home/js").Include(...);
bundles.Add(new StyleBundle("~/bundles/Areas/Home/css").Include(...);
Now I can either define multiple layout files or just selectively add bundles to the views.

active gmap4rails map into fancybox lightbox

I feel that I'm missing something very stupid but I was stucked all day with this and didn't found anything to sorted it out. I want to load a map with an user marked in it when a fancybox lightbox is called, the following code is the best and minimal approach that I have but I'm getting:
ReferenceError: Can't find variable: google
= link_to image_tag('map.png'), map_vendor_path(#coupon.vendor), class: 'js-show-map'
:javascript
$(document).ready(function(){
$('.js-show-map').fancybox({
onComplete: function(){
Gmaps.loadMaps();
Gmaps.map.addMarkers([{"lng": "7.859409", "lat": "48.023551"}]);
}
});
});
the following view is called when click in link
map.html.haml
//
it's here just for test
= stylesheet_link_tag 'gmaps4rails.css'
= javascript_include_tag "gmaps4rails/gmaps4rails.base"
= javascript_include_tag "gmaps4rails/gmaps4rails.googlemaps"
= gmaps4rails(#vendor.to_gmaps4rails)
= yield :scripts
application.js
...
//= require_tree ./templates
//= require_tree ./gmaps4rails
application.css
//= require gmaps4rails
I checked head source code and I see
<script src="/assets/gmaps4rails/gmaps4rails.base.js?body=1" type="text/javascript"></script>
<script src="/assets/gmaps4rails/gmaps4rails.googlemaps.js?body=1" type="text/javascript"></script>
Map loads fine when not in the lightbox. Any help will be appreciated, thanks.
I guess the problem is the following:
you click the fancybox
it retrieves gmaps4rails html and scripts
external scripts aren't loaded on the fly
So you should:
include manually the js dependencies in your root view
disable the external js dependencies inclusion (not mandatory though)