Mor*_*gan 1 haml ruby-on-rails angularjs
我正在尝试将我的全栈导轨应用程序一次移动到Angular页面.我正在使用ui-router(https://github.com/angular-ui/ui-router)和angular-rails-templates(https://github.com/pitr/angular-rails-templates).我假设nghaml扩展允许我继续在我的haml中使用rails helper,例如link_to,paths等,所以只需将我的haml页面复制并粘贴到模板中; 在理想的世界中,我现在处于一个页面,即客户端提供一个页面,而其他每个页面(包括它链接到的页面)仍然在服务器端提供服务.相反,我得到的错误如下:
undefined local variable or method `dashboard_patients_path' for #<Object:0x007fc87865cff0>
Run Code Online (Sandbox Code Playgroud)
和link_to等
我认为这个(带有客户端haml的angularjs)将是一个可靠的解决方案,特别是sharpper的响应,因为它似乎直接适用.
module CustomHamlEngine
class HamlTemplate < Tilt::HamlTemplate
def evaluate(scope, locals, &block)
scope.class_eval do
include Rails.application.routes.url_helpers
include Rails.application.routes.mounted_helpers
include ActionView::Helpers
end
super
end
end
end
Rails.application.assets.register_engine '.haml', CustomHamlEngine::HamlTemplate
Run Code Online (Sandbox Code Playgroud)
但是,即使重新启动服务器,也没有骰子.
思考?
小智 6
遇到了同样的问题并在调查angular-rails-templates之后找到了解决方案,仔细阅读他们的文档并使用sharpper在angularjs中提出的解决方案与客户端haml.
angular-rails-templates需要重新创建haml引擎的mimeless版本.因此,他们扩展了使用Tilt注册的类,而不是使用添加到资产管道中的引擎.因此,我们创建并向资产管道注册的新CustomHamlEngine永远不会被angular-rails-template使用.我们需要做的是用Tilt注册引擎.
在config/initializers文件夹中创建一个名为angular_rails_templates.rb的文件,并将此代码放入其中.
# config/initializers/angular_rails_templates.rb
module CustomHamlEngine
class HamlTemplate < Tilt::HamlTemplate
def evaluate(scope, locals, &block)
scope.class_eval do
include Rails.application.routes.url_helpers
include Rails.application.routes.mounted_helpers
include ActionView::Helpers
end
super
end
end
end
Tilt.register CustomHamlEngine::HamlTemplate, '.haml'
Run Code Online (Sandbox Code Playgroud)
这将覆盖通常的.haml引擎和我们刚创建的引擎.Angular-rails-templates将处理您的haml文件,它将支持rails助手以及路径助手.
包含文件后,请不要忘记重新启动服务器.
| 归档时间: |
|
| 查看次数: |
1124 次 |
| 最近记录: |