Ruby & Ruby On Rails Interview Preparation- Part 3(Rails)
- What is the asset pipeline in Ruby on Rails?
It provides a framework to concatenate and compress or minimize Javascript and css contents..
It is enabled as default with the help of sprocket-rails gem.
Concatenation helps in making one master file for js and one for css, since Web browsers are limited in the number of requests that they can make in parallel, so fewer requests can mean faster loading for your application. It adds a SHA256 hash to end of each file, since browsers cache it, every time there is an update in the file, it updates this hash, browser then removes that copy and fetches a new one.
Compression works by removing the white spaces and comments.
It also provides the ability to write CSS or Js in other language or pre processors as well like coffee-script or sass
2. What are the different type of caching techniques that you can use in Rails?
- Page Caching — Pages served by the web server, we need to implement cache expiration
- Action Caching — If we have before filters, we use this, results served from cache copy.
- Fragment Caching — Different parts of page need to be cached and expired separately, we use fragment caching, it is updated every time the object is updated. We can use it over collections too.
- Russian Doll Caching — If we have nested caches, then the innermost updation won’t let you change the outermost cache, for that add touch :true to your association.
- Low Level Caching — Rails.cache.fetch
- SQL Caching — By default all the queries once run inside an action, wouldn’t need to run again, if persistent caching is needed we can always use Low Level caching.
- Conditional Get Support — Conditional GETs are a feature of the HTTP specification that provide a way for web servers to tell browsers that the response to a GET request hasn’t changed since the last request and can be safely pulled from the browser cache.
3. Difference between after_filter, before_filter, around_filter ?
4. What are strong parameters in Rails?
