ajax - Form response for many different pages in Ruby on Rails -


In Ruby on Rail, I have an admin in an update method, called by AJAX request from both different HTTP requests and many different pages. For example, the user can use the edit page of the controller, which update depends on the user's JS either through the normal HTTP or AJAX. On the other hand, users can call the index method by update via AJAX.

How do I send different responses to all these scenarios? A separate RJS file for edit and index ? Is it a good idea to create different update methods for each "scenario"?

How much responses do we have in common with different pages? Obviously JS response is not going back which will react to HTML. As you probably know, the JS version should be used only to update parts that need to be updated, while the HTML version can update the entire page.

If most HTML reactions are the same / all common, the JS responses are the same, you should break the bits that partially not appear in all the reactions. You can toggle your display by passing extra parameters in the link.

I like partial thoughts with the situation around or not, but there is no reason that you can not do partial RJS. I have not tested this, but seeing RJS file as the only Ruby code is that you should be able to need to include another RJS file partially.

The code you want to know to get this work done:

Adding an extra parameter to a link:

Old fashioned way:

  & lt;% = Link_to_remote "I'm a remote link" ,: url = & gt; {: Controller = & gt; Controller ,: verb = & gt; Action ,: ID = & gt; @ Anything: last_action = & gt; Consultation [: verb]}%>  

Web site:

  & lt;% = link_to_remote "I'm a remote link", moderator_rill (@ anything :: last_action = & gt; ; Parameter [: Action])% & gt;  

RJS code

  page. Place_tyll: only_replaced_from_edit ,: partial = & gt; 'Was_edit' if the consultation [: last_action] == "edit" page. Place = html: only_replaced_from_index ,: partial = & gt; 'Is_index' if the consultation [: last_action] == "index" page. Place = html: not_replaced_from_edit ,: partial = & gt; Parameters [: last_action] == "edit"  

goes to the same regular HTML requests as 'Isnt_edit' in common / unique partial loads based on abstract and parameter . It should be simple because you do not need to worry about existing elements.


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -