0

What I am trying to do is fill in a form in Rails 4 with data being received from a JSON object.

#_form.html.erb  
<%= simple_form_for(@tournament) do |f| %>
 <%= f.input :url %>
 <%= f.input :name %>
 <%= f.input :location %>
 <%= f.input :start_time, :as => :hidden %>
 <%= f.input :end_time, :as => :hidden %>
 <%= f.input :entrants, :as => :hidden %>
 <%= f.input :t_id, :as => :hidden %>
 <%= f.input :type, :as => :hidden %>
 <%= f.button :submit %>
<% end %>

How do I take the input URL and use the received JSON object to populate the rest of the fields?

2
  • What is question here? Commented Jul 3, 2015 at 15:42
  • I reworded it. I want to take a URL input and use the JSON object from the URL to populate the rest of the fields. Commented Jul 3, 2015 at 15:47

1 Answer 1

2

If I've well understood you're problem is not in the view but in the controller. Just check how you're building the @tournament object.

Normally if something like :

@tournament = Tournament.new(params[:tournament])

on the JS side you should post parameters in this way :

$.ajax({
    type: "POST",
    url: '/tournaments',
    dataType : 'json',
    data: { tournament: {t_id: 1, ...} }
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.