我想在rails gem中使用我的控制器中的动态路径.
我加入了
module MyGem
class FooController < Config.controller
before_action ->{ append_view_path "app/views/my_gem/#{wizard_name}" }
...
Run Code Online (Sandbox Code Playgroud)
在视图中我需要指定路径
app/views/my_gem/#{wizard_name}/my_gem/foo/some.erb
Run Code Online (Sandbox Code Playgroud)
是在Rails中某种方式,削减gem命名空间的相对路径,并获取查找路径如何?
app/views/my_gem/#{wizard_name}/some.erb
# or
foo/bar/some.erb
Run Code Online (Sandbox Code Playgroud)
谢谢!
UPD:
据我所知,有与禁用方法isolate_namespace的Engine,但我相信,这是不是最好的和唯一的选择.
UPD2:对于Rails4,这个想法非常有用https://coderwall.com/p/p_yelg/render-view-outside-of-a-controller-in-rails-4
我想在pixelarity的Rails 4.2.6 app模板中使用(比如这个例子http://pixelarity.com/elemental).
所以,我在main.js(片段)中有一个有趣的构造
skel.init({
reset: 'full',
breakpoints: {
'global': { range: '*', href: 'style.css', containers: 1400, grid: { gutters: 48 } },
'wide': { range: '-1680', href: 'style-wide.css', containers: 1200 },
'normal': { range: '-1280', href: 'style-normal.css', containers: '100%', grid: { gutters: 36 } },
'narrow': { range: '-960', href: 'style-narrow.css', grid: { gutters: 32 } },
'narrower': { range: '-840', href: 'style-narrower.css', containers: '100%!', grid: { collapse: true } },
'mobile': { range: '-736', href: 'style-mobile.css', …Run Code Online (Sandbox Code Playgroud) 我正在阅读一篇关于Ruby 1.9的文章.有很多的用途call与方法Object.
但是使用最新版本的Ruby,我得到了这个:
BasicObject.methods.include? :send # => true
BasicObject.methods.include? :call # => false
Object.methods.include? :call # => false
def foo
puts 'text'
end
Object.send :foo # => text
Object.call :foo # => NoMethodError: undefined method `call' for Object:Class
Run Code Online (Sandbox Code Playgroud)
我认为在某些版本的Ruby(可能是1.9)中,方法被重命名.但我不确定.请说清楚.
有一个很好的技巧可以帮助找到继承的子类:
class SubClasses
@@subclasses ||= []
def self.inherited subclass
@@subclasses << subclass
end
def self.subclasses
@@subclasses
end
end
Run Code Online (Sandbox Code Playgroud)
此外,我发现使用Foo.included_modules.
但它在 上不可用Module。我如何获取包含模块的所有类?是否可以?
更新
解决了!