【发布时间】:2014-04-02 04:42:40
【问题描述】:
我正在开发 Rails 3.2 + AngularJS 应用程序,并将我所有的 angularJS 代码放在名为“api_path”(EG:/api#)的 rails 路由下
在我的 AngularJS 模板中设置指向 CRUD 函数(例如“显示”)的链接时,我一直在执行以下操作;
<td><a href="/api#/costings/{{costing.id}}">Show</td>
我的 AngularJS 模板在资产管道中并命名为 show.html.erb。我知道它正在正确编译 erb,因为我可以做到 并且有效。
我的 application_helper.rb 文件中有这样的方法;
def link_to_api(title, path)
link_to title, api_path + "#" + path
end
如果我尝试在我的 AngularJS 模板中使用它,我会收到错误:
NoMethodError at /costings/index.html.erb
=========================================
> undefined method `link_to_api' for #<#<Class:0x007f4e8f550340>:0x007f4e9391ab20>
(in app/assets/templates/costings/index.html.erb)
app/assets/templates/costings/index.html.erb, line 8
这是我在模板中尝试过的
<td><%= link_to_api("Show", "costings/{{costing.id}}") %></td>
【问题讨论】:
标签: javascript ruby-on-rails ruby-on-rails-3 angularjs