【问题标题】:Load sample JSON into Rails form将示例 JSON 加载到 Rails 表单中
【发布时间】: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


    【解决方案1】:

    请在此处查看示例http://jsfiddle.net/8drhX/1/,而不是从 rails 渲染链接,我在 javascript 中创建了它们。我认为这是更方便的方式

    【讨论】:

      猜你喜欢
      • 2014-11-13
      • 1970-01-01
      • 1970-01-01
      • 2023-03-07
      • 1970-01-01
      • 1970-01-01
      • 2018-07-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多