【发布时间】:2011-11-02 23:43:59
【问题描述】:
我正在尝试将列出的解决方案 here 集成到我的 rails (3.1) 应用程序中。
我有一个底部带有一些链接的基本表单,用于从 JSON 文件加载一些示例数据。
app/views/users/new.html.erb
<%= form_for(@user) do |f| %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :email %><br />
<%= f.text_field :email %>
</div>
<% end %>
<%= link_to "Load alice", "#" %>
<%= link_to "Load bob", "#" %>
public fixtures/sample.json
{ "name" : "alice", "email" : "alice@alice.com",
"name" : "bob", "email" : "bob@bob.com" }
设置链接以将示例数据加载到表单中的正确方法是什么?我知道我可以只使用 onclick 事件来调用 js,但这会非常混乱..
【问题讨论】:
标签: ruby-on-rails json forms