Finally fix markdown formating issue in publish_subscribe.md
This commit is contained in:
parent
38cbd47a2f
commit
047a3f63c1
1 changed files with 15 additions and 15 deletions
|
@ -12,29 +12,29 @@ The process can be divided in two steps: **1.** AJAX database manipulation and *
|
||||||
|
|
||||||
**(iii)** The database manipulation is finished by the rendering of, e.g., `stock_articles/create.js.erb`. The key task there is to **publish** the database changes by calling `trigger`, i.e.,
|
**(iii)** The database manipulation is finished by the rendering of, e.g., `stock_articles/create.js.erb`. The key task there is to **publish** the database changes by calling `trigger`, i.e.,
|
||||||
|
|
||||||
$(document).trigger({
|
$(document).trigger({
|
||||||
type: 'StockArticle#create',
|
type: 'StockArticle#create',
|
||||||
stock_article_id: <%= @stock_article.id %>
|
stock_article_id: <%= @stock_article.id %>
|
||||||
});
|
});
|
||||||
|
|
||||||
### 2. DOM updates for the particular view
|
### 2. DOM updates for the particular view
|
||||||
**(i)** Each view has the opportunity to **subscribe** to particular events of the previous step. A very simple example is the update of the `stock_articles/index` view after `StockArticle#destroy`:
|
**(i)** Each view has the opportunity to **subscribe** to particular events of the previous step. A very simple example is the update of the `stock_articles/index` view after `StockArticle#destroy`:
|
||||||
|
|
||||||
$(document).on('StockArticle#destroy', function(e) {
|
$(document).on('StockArticle#destroy', function(e) {
|
||||||
$('#stockArticle-' + e.stock_article_id).remove();
|
$('#stockArticle-' + e.stock_article_id).remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
However, in most of the situations you will like to use the full power of the MVC framework in order to read new data from the database and render some partial. Let us consider this slightly more advanced case in the following.
|
However, in most of the situations you will like to use the full power of the MVC framework in order to read new data from the database and render some partial. Let us consider this slightly more advanced case in the following.
|
||||||
|
|
||||||
The view `stock_articles/index` could listen (amongst others) to `StockArticle#create` like this:
|
The view `stock_articles/index` could listen (amongst others) to `StockArticle#create` like this:
|
||||||
|
|
||||||
$(document).on('StockArticle#create', function(e) {
|
$(document).on('StockArticle#create', function(e) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '#{index_on_stock_article_create_stock_articles_path}',
|
url: '#{index_on_stock_article_create_stock_articles_path}',
|
||||||
type: 'get',
|
type: 'get',
|
||||||
data: {id: e.stock_article_id},
|
data: {id: e.stock_article_id},
|
||||||
contentType: 'application/json; charset=UTF-8'
|
contentType: 'application/json; charset=UTF-8'
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
**(ii)** The action `StockArticles#index_on_stock_article_create` is a special helper action to handle DOM updates of the `stock_articles/index` view after the creation of a new `StockArticle` with the given `id`.
|
**(ii)** The action `StockArticles#index_on_stock_article_create` is a special helper action to handle DOM updates of the `stock_articles/index` view after the creation of a new `StockArticle` with the given `id`.
|
||||||
|
|
Loading…
Reference in a new issue