I’m trying to integrate the solution listed here into my rails (3.1) application.
I have a basic form with some links at the bottom to load some sample data from a JSON file.
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" }
What would be the proper way to set up the links to load sample data into the form? I know I could just use an onclick event to call the js, but that would be very messy..
Please check example here http://jsfiddle.net/8drhX/1/, instead of rendering links from rails I created them in javascript. It is more convenient way I think