How do I access assets on my maintenance page in rails 3.1 with the asset pipeline enabled?
With the asset pipeline enalbed all assets have a hash in their filename. However, maintenance pages are vanilla HTML, and rails/passenger is being bypassed by the apache config, so there's no way to generate the right asset paths.
I need my application.css and an image file. It's fine if they're the old ones.
I can think of a few kludges, but they're all lame:
On each deploy, symlink the assets I need to a generic name that I use in the maintenance file.
Make my maintenance page dynamic, generate it, and dump the markup somewhere - then modify my maintennce 'deploy' script.
If you want to avoid a symlink or a dynamic (erb) page, then use a static template and modify this during deployment.
First create a maintenance page template.
During deployment read the mainfest.yml file created by the precompile process.
Read in the template of the maint page.
Replace any files named in the template with the hashed version from the manifest.
Write out the altered template to the file-system.
For anyone's convenience, I adopted Richard's solution in my project and created a simple ruby script that replaces asset links in the static HTML error / maintenance pages. It is deliberatery NOT a rake task so that it is as fast as possible. It has no Rails depenency anyway, other than that it has to be run from the rails root directory.
#!/usr/bin/env ruby
require 'yaml'
GLOBS = %w(public/errors_source/*.html)
MANIFEST = "public/assets/manifest.yml"
manifest = YAML::load(File.open(MANIFEST))
GLOBS.each do |glob|
Dir.glob(glob).each do |file|
next unless File.file?(file)
contents = File.read(file)
manifest.each do |asset, compiled_asset|
contents.gsub!(asset, "/assets/#{compiled_asset}")
end
File.open(file.gsub('errors_source/',''), 'w') do |outfile|
outfile.write(contents)
end
end
end
The script expects the static HTML error/maintenance pages to live under the errors_source directory and copies them (with assets replaced for their hashed versions) to the rails root directory.
A sample maintenance page then may look like this (notice the CSS asset link and logo image - these assets are simply shared with the main rails code):
<html>
<head>
...
<link href="application.css" media="screen" rel="stylesheet" type="text/css"/>
</head>
<body>
...
<img src="logo.png" width="161" height="61"/>
...
</body>
</html>
If you are on Heroku, there's an add-on called Trackman.
You can link all your assets and it deploys your pages and assets on S3.
You practically have nothing to code.
You can use the utilities within the gem to also make the dev a piece of cake.
http://www.trackman-addon.com
Related
I would like to evaluate the features of pivot grid using simple test html without cmd.
I've read the information from those links but I still couldn't install a working environment
https://docs.sencha.com/extjs/6.0/co...ivot_grid.html
https://www.sencha.com/forum/showthr...out-Sencha-Cmd
http://se.sencha.com/setup-guide/
I've downloaded the core framework ('ext-6.0.1-trial.zip')
and pivot addon ('ext-addons-6.0.1-trial.zip') from sencha site
and unpacked them on my test web server:
www.mydummy.server.org/lib/extjs/ext-6.0.0/ <- framework
www.mydummy.server.org/lib/extjs/package/ <- addon
and tested it calling the pivots in kitchensink example with:
www.mydummy.server.org/lib/extjs/ext-6.0.0/examples/kitchensink/index.html
in such setup they start without errors.
The target location of the addon is a bit strange for me,
I was sure I should unpack addon to the package directory of the framework
www.mydummy.server.org/lib/extjs/ext-6.0.0/package/
but then the kitchensink example doesn't work
(kitchensink calls pivot with ../../../package/pivot )
Now I wonder how should I include framework and addon in own html example,
I've tried something like:
<link href="www.mydummy.server.org/lib/extjs/ext-6.0.0/build/classic/theme-neptune/resources/theme-neptune-all.css">
<script src="www.mydummy.server.org/lib/extjs/ext-6.0.0/build/ext-all.js"></script>
<link href="www.mydummy.server.org/lib/extjs/packages/pivot/build/neptune/resources/pivot-all.css">
<script src="www.mydummy.server.org/lib/extjs/packages/pivot/build/pivot.js"'></script>
<script src="www.mydummy.server.org/lib/extjs/packages/exporter/build/exporter.js"'></script>
The links are ok (no http error) but the simple pivot is not rendered
and framework couldn't load further classes:
[Ext.Loader] Some requested files failed to load.
What is the correct setup of extjs and pivot without cmd?
Thank you,
Annie
Couple things here.
For the KitchenSink, if you open up www.mydummy.server.org/lib/extjs/ext-6.0.0/ in your browser you will be shown an index.html. There will be a green button to show the examples which will point to www.mydummy.server.org/lib/extjs/ext-6.0.0/build/examples/index.html (notice the build dir in there). Then if you click on the KitchenSink it will load from www.mydummy.server.org/lib/extjs/ext-6.0.0/build/examples/kitchensink/ (once again, notice the build dir). This is due to the KitchenSink being a Cmd app which will build to that build dir. The examples dir outside the build dir is the development version of the app which is why we still provide it for the source.
Next, about how to use the pivot grid's Cmd package outside of the Cmd package. we build the Cmd package so if you look in the package's build dir you should see a built JavaScript and CSS file that you can load via <script> and <link> in your HTML.
<html>
<head>
<title>Pivot Grid Test</title>
<link href="http://releases/ext/6.0.1.250/build/classic/theme-neptune/resources/theme-neptune-all.css">
<script src="http://releases/ext/6.0.1.250/build/ext-all.js"></script>
<link href="http://localhost/ext-addons-6.0.1/packages/pivot/build/neptune/resources/pivot-all.css">
<script src="http://localhost/ext-addons-6.0.1/packages/exporter/build/exporter.js"></script>
<script src="http://localhost/ext-addons-6.0.1/packages/pivot/build/pivot.js"></script>
</head>
<body></body>
</html>
Notice I have the exporter.js loading before pivot.js and this mostly works except that I do see something that I'd call a bug for us. In pivot.js, we define Ext.ux.ajax.PivotSimlet which extends Ext.ux.ajax.JsonSimlet (which is in the framework's ux package). This is fine to extend like this but PivotSimlet would only be needed if you want to have simulated data in your application (which most wouldn't unless in dev). Two ways you can fix this, remove that class from pivot.js or include the ux's JavaScript/CSS (however that package contains a lot of code that you may not need).
Thanks a lot for your explanation.
I've added these classes to get an working example:
<script src="http://releases/ext/6.0.1.250/packages/ux/src/ajax/Simlet.js"</script>
<script src="http://releases/ext/6.0.1.250/packages/ux/src/ajax/DataSimlet.js"</script>
<script src="http://releases/ext/6.0.1.250/packages/ux/src/ajax/JsonSimlet.js"</script>
I was supplied with a custom layout for the login page of my Laravel project.
When I opened login.html file, which represents the layout for that specific page I saw such links
<!-- Base Css Files -->
<link href="assets/libs/jqueryui/ui-lightness/jquery-ui-1.10.4.custom.min.css" rel="stylesheet" />
<link href="assets/libs/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
<link href="assets/libs/font-awesome/css/font-awesome.min.css" rel="stylesheet" />
...
So I figured that I only need to copy the assets folder, which came with the template (there are all needed bootstraps, jqueries and whatnot) to my projects app\resources\assets directory
Now, when I copied the code from login.html into my login.blade.php view and copied the templates' assets folder to app\resources\assets it doesnt work. It only displays naked html code when I open the page.
What am I doing wrong in linking the assets folder?
The resources folder is (like the name says) for the resources.
If you don't want/need to build/compile/min your scripts, then just put them in the public folder, so you can access them from your template.
In your case
public/assets/libs...
In order to access assets, you have two ways to approach it. Either using Elixir/gulp or to use direct access.
Gulp is a node.js application that reads your assets files, whether JS, CSS, Coffee, etc...and combine them in single files. Gulp reads the files defined in the gulpfile.js, and you can access the output files in your blade file using elixir().
You can read more about Elixir here.
In your specific case, you can just place the files under the public/ directory. So Laravel treats public as the root directory, and if you want to read the file assets/css/foo.css just place the file in public/assets/css/foo.css
Hi i have this assets folder which has the following folder inside of css, images, uploads, and js folder i put the assets folder outside application. Im wondering that how could i keep it safe so that when users tried to type in the url like for example http:/test.com/assets it will redirect to application folder or somewhat it will says page not found. Cause ive noticed that when i type in the url http://test.com/assets it will go to the assets folder and which is vulnerable and people could see all the folders in the assets folder. can someone help me figued this thing out? Any help is muchly appreciated.
if you want to secure you folder then do one this create html file like this
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<p>Directory access is forbidden.</p>
</body>
</html>
and save it as index.html and put it on your assets folder whenever some try to access your url http://test.com/assets then this index file will execute and its shows Directory access is forbidden.
Here is the plugin code...
module Jekyll
module VersionFilter
def versioned_url(input)
"#{input}?#{Time.now.to_i}"
end
end
end
Liquid::Template.register_filter(Jekyll::VersionFilter)
I am trying to cache bust/version control my .css file. I am new to Liquid. I am having trouble figuring out this basic plugin. Any help?
You need to put version.rb into the _plugins/ directory in the root of your Jekyll site. If you don't have a _plugins/ directory, create one.
For usage - it looks like it gives a new filter that you can apply to text - so you'd use it in your templates to filter the references to your CSS files, adding the query string so that they aren't cached - but I'm sure there's more info on that wherever you got the code from.
For what it's worth, breaking caches with querystrings isn't the best solution. It'd probably be better to write a plugin that adds a new string to the actual filename, and then adds that string to the urls where those assets are included in the templates - but that is a bit more complex.
If using an existing plugin for static asset versioning is an option for you, try jekyll-minibundle.
Assuming you keep non-stamped CSS files in _styles (note the _, because you don't want these to be exported to the production site) and want the stamped CSS files to appear in css, do the following:
<link href="{% ministamp _styles/site.css css/site.css %}" rel="stylesheet" media="screen, projection">
That works fine in combination with compass, just make compass export to _styles.
I was tring out below scenario:
Approach 1: Created an resource using rails scaffold, coded all the functionality i.e. index, new, edit and delete functionality - everything is working fine.
Approach 2: Tried to create manually the controller and views for the same functionality with different name for the model created in approach 1. The functionality is working fine.
But i get an RoutingError as:
Started GET "/userwebmgmts/stylesheets/ctlCalendar.css" for 127.0.0.1 at 2011-08-29 17:08:37 +0530
ActionController::RoutingError (No route matches "/userwebmgmts/stylesheets/ctlCalendar.css"):
In Route.rb file:
added the entry for the newly created controller/view as: get "userwebmgmts/index"
Can anyone help tell why i am getting the error for the controller created manually and not getting the error for the resources created using scaffold?
Thanks,
Sudhir C.N.
This is just a shot in the dark from the information you provided but...
Rails routes work in an order first a rack application checks the /public/ folder in the root of your application. If there is a matching file then it will load that.
Rails 3.1
If not it will load up the assets folder and create the pipe line and then check the application.css and application.js
Then it will load up the routes file and start ticking though your routes
If no route matches then you will get an exception thrown.
Your Problem
Your problem probably comes from the fact that your css is in the wrong place
With your file structure
/userwebmgmts/stylesheets/ctlCalendar.css
You should have a link in the page header that looks like this
<link rel="stylesheet" href="/userwebmgmts/stylesheets/ctlCalendar.css" type="text/css" media="screen" title="no title" charset="utf-8">
And the file should be located at
/public/userwebmgmts/stylesheets/ctlCalendar.css