logo
down
shadow

How can I get a rails controller to execute different javascript when called from different pages in my app?


How can I get a rails controller to execute different javascript when called from different pages in my app?

By : user2955797
Date : November 22 2020, 10:48 AM
Does that help I solved this by using the following code in the sales_opportunities controller:
code :
    if @sales_opportunity.company.id?
      @company = @sales_opportunity.company
    else
      @company = Company.new(organization_id: params[:organization_id])
    end
if (/companies/.test(self.location.href)) { ... };


Share : facebook icon twitter icon
How to execute a javascript returned by controller in Rails?

How to execute a javascript returned by controller in Rails?


By : LIANG CHEN
Date : March 29 2020, 07:55 AM
To fix this issue try to use remotipart gem:
http://github.com/JangoSteve/remotipart
ZF2 - Injecting pages to navigation before controller is called

ZF2 - Injecting pages to navigation before controller is called


By : Emil Persson
Date : March 29 2020, 07:55 AM
I wish this helpful for you The navigation containers are composed by factory classes. The easiest approach is to write your own factory and have the getPages() method fetch pages from a database instead of from config. If you extend from the AbstractNavigationFactory you only need to write a couple of methods.
code :
<?php
namespace Application\Navigation\Service;

use Zend\Navigation\Service\AbstractNavigationFactory;
use Zend\ServiceManager\ServiceLocatorInterface;

class CmsNavigationFactory extends AbstractNavigationFactory
{
    /**
     * @param ServiceLocatorInterface $serviceLocator
     * @return array
     * @throws \Zend\Navigation\Exception\InvalidArgumentException
     */
    protected function getPages(ServiceLocatorInterface $serviceLocator)
    {
        if (null === $this->pages) {

            $application = $serviceLocator->get('Application');
            $routeMatch  = $application->getMvcEvent()->getRouteMatch();
            $router      = $application->getMvcEvent()->getRouter();

            // get your pages from wherever...
            $pages       = $this->getPagesFromDB();

            $this->pages = $this->injectComponents($pages, $routeMatch, $router);
        }
        return $this->pages;
    }

    public function getName()
    { 
         // this isn't used if fetching from db, it's just here to keep the abstract factory happy
         return 'cms';
    }
}
'service_manager' => array(
    'factories' => array(
        'CmsNavigation' => 'Application\Navigation\Service\CmsNavigationFactory',
    ),
),
<?php echo $this->navigation()->menu('CmsNavigation'); ?>
Execute Javascript function from Rails controller (without rendering or reloading the view)

Execute Javascript function from Rails controller (without rendering or reloading the view)


By : Sharon B.A
Date : March 29 2020, 07:55 AM
Hope this helps What you want is AJAX. JavaScript will then have to do something intelligent with the HTTP response body in the success callback if using a JavaScript library, like jQuery, or if the readyState is 4 and the status is 200 if using native JavaScript.
You're stuck with the HTTP request-response lifecycle.
code :
<ol id="comments"></ol>

<script type="text/javascript">
    var xhr = new XMLHttpRequest();

    xhr.onreadystatechange = function() {
        if (this.readyState === 4 && this.status === 200) {
            document.getElementById("comments").innerHTML = this.responseText;
        }
    };

    xhr.open("GET", "/posts/123/comments_ajax");

    xhr.send(null);
</script>
class PostsController < ApplicationController

    def comments_ajax
        @comments = Comment.where(:post_id => params[:id])
    end

end
<%= @comments.each |comment| do %>
    <li><%= comment.text %></li>
<% end %>
rails execute the view without execute the controller's action

rails execute the view without execute the controller's action


By : Laura Webb
Date : March 29 2020, 07:55 AM
this will help Your contact_send is pointing to desktop#contact action. But your controller doesn't show a contact action. So your contact_send action isn't called.
Change
AngularJS execute code when changing pages that use same controller

AngularJS execute code when changing pages that use same controller


By : Wangmo
Date : March 29 2020, 07:55 AM
I wish this helpful for you I have a PhoneGap app, that has multiple html pages. , There are so many ways you could do that, one of them:
code :
// inside your controller
angular.element(document).ready(function () {

// your code 

});
<div ng-controller="myCtrl" ng-init="someinitfunc()"></div>
Related Posts Related Posts :
  • Build Fails: `npm rebuild node-sass --force`
  • Angular Datepicker change dateformat
  • Trying to extract data from between two sets of characters
  • Configuring Jest in WebStorm
  • Uncaught Error: Syntax error, unrecognized expression: tr.ec_portfolio_title,
  • JQuery fading in fading out continuously
  • Unexpected end of input (Line 1) and Undefined Function?
  • How to animate the width of a div slowly with jquery
  • JavaScript + RegEx Complications- Searching Strings Not Containing SubString
  • SignalR - Unable to get property 'client' of undefined or null reference
  • full calendar not displaying when loaded (with backbone)
  • Angular: Update service and share data between controllers
  • ReplaceAll Google script
  • Search for matching LI items in separate UL
  • Access arguments of an... argument
  • Customizing Google custom search jsapi (query strings)
  • React | Can´t load Images > Module not found
  • Dynamically creating buttons in DOJO
  • 404 Not Found in AJAX post call
  • How do I find out, using javascript, what software opened and running my application?
  • Javascript to check the status of wireless connection
  • StarDict support for JavaScript and a Firefox OS App
  • Phonegap event Resume
  • call javascript function on ENTER key press?
  • When is the best time to remove no-js classes from the html tag
  • Recommended email sending languages
  • setInterval not working properly with chrome
  • Does IE create new scope for each script tag?
  • Uncaught SyntaxError: Unexpected token < Underscore and parse issues
  • How to pass captured URL to Email Body in HTML
  • How to structure default nested resources?
  • Store all the keys of a JSON object in a variable
  • Need an efficient way to group the Array of object in javascript
  • a sensible approach to highcharts x-axis labels
  • IDE autocompletion for javascript AMD loading style
  • Bootstrap menu disappears after first click setting the ul style to none
  • split ajax json response errors in each field
  • how to add javascript in head in cmsms
  • REGEX: Finding the correct occurrence order of some given special characters in a string
  • How do you preserve a JavaScript date's time zone from browser to server, and back?
  • Return binary result from phantomjs webserver
  • must be listed in the web_accessible_resources manifest key in order to be loaded by pages outside the extension.
  • Replacing a substring of an element's text with another string
  • How do I filter marks greater than or equal to 90 in this array?
  • Modify the text of my radio input button?
  • Clicking on status bar does not scroll to top of app (Trigger.io)
  • Mocha JS: How to highlight specific assertion failure?
  • $.getJSON jquery parsing to HTML
  • Find items of a certain class (a) that are also in other classes (b,c,d)
  • Setting different images for D3 force-directed layout nodes
  • Integrating Dropzone.js with angular
  • Control sprite animation speed
  • Can only one error / success function be assigned for AngularJS $http promises?
  • Working with math in javascript
  • Django variable isnt recognized by javascript
  • $.when does not work with $.scrollTo plugin
  • How to read local xml file using $.ajax?
  • Manifest is not Valid JSON. What is wrong?
  • AngularJS re-initialise JS after statechange
  • WebRupee is not working
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org