Rails multistep form with ajax

61 views
Skip to first unread message

Seth Portman

unread,
Aug 1, 2013, 2:37:40 PM8/1/13
to rubyonra...@googlegroups.com
I am following Railscasts #217 and I have been able to make everything work using html protocol the only issue is that I need it to use ajax protocol instead. My question and code is very similar to stackoverflow question Multistep forms in Rails using AJAX . I understand how to setup ajax and make the form sumit remotely my question though is how do I pass over the forms variable i.e. "f" as in "<%= form_for @post do |f|>" Any help is appreciated.

Robert Walker

unread,
Aug 2, 2013, 10:03:10 AM8/2/13
to rubyonra...@googlegroups.com
Seth Portman wrote in post #1117487:
> I am following Railscasts #217 and I have been able to make everything
> work
> using html protocol the only issue is that I need it to use ajax
> protocol
> instead. My question and code is very similar to stackoverflow question
> Multistep
> forms in Rails using
>
AJAX<http://stackoverflow.com/questions/14228368/multistep-forms-in-rails-using-ajax>
> .
> I understand how to setup ajax and make the form sumit remotely my
> question
> though is how do I pass over the forms variable i.e. "f" as in "<%=
> form_for @post do |f|>" Any help is appreciated.

I think you're probably making this too complicated. If you're using
JavaScript anyway then just have one page, with one form. Use JavaScript
(no AJAX required) to show and hide the fields for the various steps in
the process. Ryan mentioned, and recommended, this approach at the
beginning of the episode.

Since have have only a single page with a single form there's nothing to
pass around. The are no changes required in your controller or model
classes. As far as Rails is concerned it's no different than a regular
form submission.

If your multi-step form is extremely complex then I might suggest
considering one of the single page app solutions such as Ember.js,
Backbone.js or Angular.js.

--
Posted via http://www.ruby-forum.com/.
Reply all
Reply to author
Forward
0 new messages