bastos (owner)

Revisions

gist: 60845 Download_button fork
public
Public Clone URL: git://gist.github.com/60845.git
Embed All Files: show embed
Ruby #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
...
 
before_filter :set_views_paths_for_layout
 
 
# Add new paths to templates paths.
def set_views_paths_for_layout
  paths = []
...
  paths << create_a_new_path("#{RAILS_ROOT}/app/views/shared")
...
  paths.each do |_path|
    prepend_view_path _path if not view_paths.include?(_path)
  end
end
 
# This method returns a ActionView::PathSet::Path object.
# Use-it instead of create a new instance every request couse if you do, will couse
# a lot of use of your File System (stat, stat64). Issue fount using Dtrace tool: dtruss.
# The SOLUTION is memoize this method and store all the results.
#
# ====References:
# http://apidock.com/rails/ActionView/Base/process_view_paths/class
# http://apidock.com/rails/ActionView/Base/new/class
# http://apidock.com/rails/ActionView/PathSet/type_cast/class
#
# ====Example:
# create_a_new_path("#{RAILS_ROOT}/app/views/otherpath")
def create_a_new_path(path)
  @@paths_already_set ||= {}
  return @@paths_already_set[path] if @@paths_already_set.has_key?(path)
  @@paths_already_set[path] = ActionView::PathSet::Path.new(path)
  return @@paths_already_set[path]
end
 
...