Confusion around form_for defaults and json/js

73 views
Skip to first unread message

Jonathan Allard

unread,
Jun 18, 2015, 2:41:53 AM6/18/15
to rubyonra...@googlegroups.com
With Convention over configuration, you can usually trust the defaults to get you there. In this case, not so much. I've been banging my head on the wall for a few hours now, in between trying things and researching.

For the usual cases, how do I set up an AJAX form. Is it using JS or JSON format?

**Case 1: `form_for remote: true` default, `format.js`**

UJS sends a request as JS. 
Exception: Missing template for update.js.

`form_for remote: true, format: :json`

No difference in HTML output, though `form_for` doc examples says you can do that.

**Case 2: `form_for remote: true, html: {"data-type" => :json}` not the default**

Responder will answer 204, but why is this not default in either `form_for` or UJS?

What is the expected use case and can it be documented? I suspect it's the latter, but I expected there to be good defaults in place.

Elizabeth McGurty

unread,
Jun 18, 2015, 8:29:57 AM6/18/15
to rubyonra...@googlegroups.com
Check out RailsCasts:

Ruby on Rails - Railscasts PRO #136 jQuery & Ajax (revised)

https://www.youtube.com/watch?v=FBxVN7U1Qsk

Jonathan Allard

unread,
Jun 25, 2015, 6:04:44 PM6/25/15
to rubyonra...@googlegroups.com
Railscasts does a lot of configuration before having it working. Why is there not a functioning default?


Responder will answer 204, but why is this not default in either `form_for` or UJS?

What is the expected use case and can it be documented? I suspect it's the latter, but I expected there to be good defaults in place.
 

Jonathan Allard

unread,
Jun 25, 2015, 6:05:56 PM6/25/15
to rubyonra...@googlegroups.com
I'll include the ASCIIcast for brevity for others: http://asciicasts.com/episodes/136-jquery
Reply all
Reply to author
Forward
0 new messages