P
P
Pavel2012-07-16 09:25:47
Ruby on Rails
Pavel, 2012-07-16 09:25:47

How to implement a complex AJAX form with multiple models?

I am new to Rails and have already realized that Rails has its own best practices for all occasions.
The situation is as follows: there are 2 models: Request and Client.
I want to implement the form like this:

  • When creating a new Request, the user first displays only 1 field "phone number" and the "search" button.
  • When you click on "search", we look for this number in the clients table. If it is, then we show the client card and the fields related to the application.
  • If there is no client with such a number in the database, then we show the fields for creating a new client and the fields related to the application.
  • Well, accordingly, when you click the "save" button, these models should be saved to the database. Any advice on how to do this without reloading the page in AJAX and in keeping with the best traditions of the Rails Way?

I use the latest versions of Rails and Ruby.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anatoly, 2012-07-16
@taliban

And rails don’t care how many forms you have if you do everything with Ajax? You will have 3 addresses there:
1. show the search form / search by number
2. show the card if the user is found
3. form for creating a client
And you will make requests to these addresses with Ajax (I don’t know what is in the rails, controllers?)

P
Pavel, 2012-07-17
@region23

Found the answer on railscasts.com
1. Unobtrusive JavaScript railscasts.com/episodes/205-unobtrusive-javascript
2. PJAX railscasts.com/episodes/294-playing-with-pjax

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question