From 99f9d070738ff5698fb7628857585a5903d619f7 Mon Sep 17 00:00:00 2001 From: Karl Bryan Paragua Date: Mon, 7 Mar 2016 13:36:59 +0800 Subject: [PATCH] Update README.md --- README.md | 76 +++++++++++++++++++++---------------------------------- 1 file changed, 29 insertions(+), 47 deletions(-) diff --git a/README.md b/README.md index 82ec280..8c6fcad 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,8 @@ Articles.prototype.edit = function(){ // Handle edit article }; ``` -Or use pass the prototype directly as the 2nd argument of the `controller` method. + +Or pass the prototype value directly as the 2nd argument of the `controller` method. ```js Paloma.controller('Articles', { @@ -224,43 +225,39 @@ You can manipulate what controller/action should Paloma execute by calling `js` ## Passing Parameters -You can access the parameters on your Paloma Controller using `this.params` object. +You can pass parameters to your Paloma Controller in two ways. - -1. Parameters only. +1. Passing a hash. (*parameters only*) - `users_controller.rb` - ```ruby - def destroy - user = User.find params[:id] - user.destroy + ```ruby + def show + user = User.find params[:id] - js :id => user.id - end - ``` - - Paloma controller. - - ```javascript - Paloma.controller('Users', { - destroy: function(){ - alert('User ' + this.params['id'] + ' is deleted.'); - } - }); + js :id => user.id + end + ``` + +2. Passing path and a hash. + + ```ruby + def show + user = User.find params[:id] + + js 'Admin/Users', :id => user.id + end ``` -2. Path with parameters. +Using both ways, you can access the passed params using the `params` property of your Paloma controller. + +```javascript +Paloma.controller('Users', { + show: function(){ + alert("User id: " + this.params.id); + } +}); +``` + - ```ruby - def destroy - user = User.find params[:id] - user.destroy - - js 'Accounts#delete', :id => user.id - end - ``` - - ## Preventing Paloma Execution If you want to Paloma not to execute in a specific Rails Controller action you need to pass `false` as the Paloma parameter. @@ -355,8 +352,6 @@ Ideally, you just need to call `insert_paloma_hook` in your layouts, since the l ## Turbolinks Support -As of version `4.1.0`, Paloma is compatible with Turbolinks without additional setup. - ### Execute Paloma when user hits `Back` or `Forward` button. Paloma executes page-specific javascript by adding a `