I have installed livereload gem, which I'm using with a ruby middleman application. However, it's only autoloading changes to the css. If I make changes to the html files, I still have to restart the server to view the changes. Is there somehow I can make it autoload html changes?
It seems that this feature doesn't work on all versions of livereload and also depends on the browser and it's extensions. Try to also change a css file when you change the html so that the refresh occurs. Also, have you looked at https://github.com/guard/guard-livereload ? That has an example watching the change of html.
guard 'livereload' do
watch(%r{app/views/.+\.(erb|haml|slim)})
watch(%r{app/helpers/.+\.rb})
watch(%r{public/.+\.(css|js|html)})
watch(%r{config/locales/.+\.yml})
# Rails Assets Pipeline
watch(%r{(app|vendor)(/assets/\w+/(.+\.(css|js|html))).*}) { |m| "/assets/#{m[3]}" }
end
Related
I'm using the livereload plugin for guard in combination with the chrome extension. It's working nicely and my browser refreshes whenever a source file is changed.
It seems like Meteor has this functionality without requiring a chrome extension. Is there any similar library for the ruby world, to hot-push ui changes?
Instead of using the browser plugin, use Rack::LiveReload. It will send events to the browser via web sockets and cause the browser to reload when watched changes occur.
I just migrated my rails 2.3 application to rails 3.2 (a bit late but I did it)
Everything else seem to work fine except I get no route error for images which are referred to by javascript stylesheets.
The rake assets:precompile task creates all the image names with appended hash also for images which are required by js stylesheets for example jquery dialog etc.
How can I fix this?
I have an annoying problem with my new grails app. I'm trying to mock up a design for a site that I will be making but whenever I do changes in my css it won't affect the running application. No matter how big changes I do I have to stop the application and then run it again.
This is very frustrating, I've turned of cache in Chrome and even if I go to the specific document the resource is still the old. What can I do to solve this problem? I can make changes in my gsp files and the changes will appear but not in my css.
I am currently loading the resource within a layout file like this:
<link rel="stylesheet" href="${resource(dir: 'css', file: 'app.css')}" type="text/css">
If you need me to provide any more information, please just ask. I am using grails 2.2.0.
Add this to your Config.groovy (probably just for development)
grails.resources.debug = true
Read the docs for more info.
It looks like Gregg's answer doesn't work for 1.3.7 (maybe that is something added in 2.x?). A method I found that makes quick CSS updates possible is to include a separate GSP as a template in the page header.
That is, create a file called "_css.gsp" (underscore prefix is required) in the same directory as your view files, fill it with standard css surrounded by html style tags, and then include the following in your layout header or page:
<g:render template="css" />
With that in place, the content of _css.gsp is injected into the page. And I can make changes to _css.gsp and they are immediately reflected after page refresh without having to restart Grails. Hope this helps someone in Grails pre-2.x!
I am using Sinatra and erb on Passenger/Apache. Every time I made edit to the erb file, I have to restart Apache and refresh in the browser.
Is there any way to edit the file and sinatra can instantly update it? I mean simply by clicking the refresh button in the browser can one view the update?
Conclusion:
If you are in dev on sinatra, you can use shotgun or SinatraLoader.
If you are using Passenger, you can create an empty file: tmp\always_restart.txt
Yes, you can use Sinatra::Reloader.
Sinatra::Reloader
Extension to reload modified files. Useful during development, since it will automatically require files defining routes, filters, error handlers and inline templates, with every incoming request, but only if they have been updated.
You can use Shotgun for that: https://github.com/rtomayko/shotgun
Shotgun
This is an automatic reloading version of the rackup command that's shipped with
Rack. It can be used as an alternative to the complex reloading logic provided
by web frameworks or in environments that don't support application reloading.
At the moment my application.js file looks like this:
//= require_tree ./vendor
//= require_directory ./lib
I also have individual JavaScript files for individual views, e.g. home.js, user.js etc.
Do people put these files in the application.js? If so how do they activate them? Most of my JavaScript is executed from the jQuery ready event handler $(function (){ });
Obviously this does not work if they are all in the same file. How could I minify these files and access the correct ready event if they are all in the same file?
Any help or tips greatly appreciated.
It's fine to have multiple jQuery document ready handlers as you shouldn't care about the order between them. You'll need to check that the elements they work on exist before trying to attach any handlers, though.
For example, in home.js, you might have something like
if ($("#home_div").length) { // do some stuff on the home page }
Doing this is better than splitting up your JS and only serving some pieces on some pages, since with the compiled approach your users only have to download JS once. I think the default rails 3.1 config should minify and concatenate all of your JS in production but not in dev. If you want to enable it manually,
config.assets.compress = true # compress js into one file
config.assets.js_compressor = :uglifier # minify the JS (need the uglifier gem)
config.assets.digest = true # append hashes to filenames so you can set far-expiry headers for caching
some more info, check out the "customizing the pipeline section" of the docs http://guides.rubyonrails.org/asset_pipeline.html#customizing-the-pipeline
and this related question
How to properly work with jQuery in Rails 3.1 asset pipeline?