blu*_*l2k 5 ruby-on-rails ruby-on-rails-3
如何在不必在文件名前面提供"_"的情况下渲染部分?有没有我可以调用的参数不使用它?
使用RABL和Backbone弹出了这个问题 - 使用RABL要求我在我的视图中有一个文件,如"index.json.rabl".但是,当我在页面加载时使用JSON时(正如Backbone一样),我需要调用文件"_index.json.rabl".这两个文件完全相同,只需要有不同的名称.我只想使用1个文件"index.json.rabl"并强制render()函数查找该文件名,而不是"_".
=>编辑
人们在下面描述的标准解决方案不起作用.这可能是一个RABL问题呢?以下代码始终转到views/countries/_index.json.rabl文件.
在我的.erb文件中
countryList.reset(<%=get_json("countries", "index", @countries)%>);
Run Code Online (Sandbox Code Playgroud)
在我的application_helper.rb文件中
def get_json(view_path, view_action, object)
path = view_path + '/' + view_action + ".json"
return raw(render(path, object: object, :formats => [:rabl]))
end
Run Code Online (Sandbox Code Playgroud)
<div id="articles" data-articles="<%= render(template: "articles/index.json.rabl") %>" >
Run Code Online (Sandbox Code Playgroud)
从这里开始,然后找出问题所在。但很明显这render template: path就是您想要的语法。
| 归档时间: |
|
| 查看次数: |
1511 次 |
| 最近记录: |