controllers

Handling an ActiveRecord error if database is empty

夙愿已清 提交于 2019-12-11 02:55:38
问题 I'm working on a rails 4 app, and i have the following controller code def index @issue = Issue.find(1) @sections = @issue.sections @articles = @issue.articles end which breaks if the database is empty with the error: "Couldn't find Issue with id=1". What is the proper way to check for this in a way that if nothing is in the db it doesn't raise an error? 回答1: One method you can use is the exists? active record method, like so: @issue = Issue.where(id: 1) if @issue.exists? # do something if it

Magento Enterprise controller override

主宰稳场 提交于 2019-12-10 22:44:27
问题 I am trying to override the Enterprise/CatalogEvent/controllers/Adminhtml/Catalog/EventController.php. The problem is the config.xml. How do I follow the naming convention of Magento. The following is the config.xml file <admin> <routers> <adminhtml> <args> <modules> <Mynamespace_catalogevent before="Enterprise_CatalogEvent">Mynamespace_CatalogEvent_Adminhtml</Mynamespace_catalogevent> </modules> </args> </adminhtml> </routers> </admin> 回答1: Based on the seemingly correct xpath and attribute

Zend Framework : Subdirectories in controllers directory

妖精的绣舞 提交于 2019-12-10 16:45:45
问题 I'm using the Zend Framework for my website, and just created a special module "api" to create... Well, an API. Now, I have a lot of controllers in my module and I'd like to create subdirectories in this controllers directory in order to "tidy" it. My new structure would be something like this : - controllers/ - controllers/contents/[controllers] - controllers/users/[controllers] - controllers/misc/[controllers] However, I find myself totally unable to find what kind of urls and redirections

Modifying BaseController in rails ActiveAdmin gem

别说谁变了你拦得住时间么 提交于 2019-12-10 13:38:25
问题 I am using the ActiveAdmin gem in a rails app. If I wanted to add a new before filter that applies to all activeadmin gems, how would I do this? I imagine I could modify the BaseController in ActiveAdmin to achieve this, but what is the proper way to make this modification from within the rails app? Is there a way to duplicate and overwrite the BaseController? 回答1: If I understand you , there is a special config for this # == Controller Filters # # You can add before, after and around filters

titanium alloy: calling controller function from another controller

余生颓废 提交于 2019-12-10 11:34:25
问题 Using SDK 3.2.0 I have a index controller that defines a function to set Android Menus. I want to call that function from a variety of controllers that are nested loaded throughout the App. Code: //index.js exports.setMenus = function(enabled) { var activity = $.index.getActivity(); activity.onCreateOptionsMenu = function(e){ /... }; activity.onPrepareOptionsMenu = function(e) { /... }; activity.invalidateOptionsMenu(); }; Alloy.Globals.Index = $; Then, way after, inside home controller , I

asp.net mvc 4 calling method from controller by button

会有一股神秘感。 提交于 2019-12-10 04:37:04
问题 In my Controllers i have class AccountController and within in i have this method [HttpPost] [ValidateAntiForgeryToken] public ActionResult LogOff() { WebSecurity.Logout(); return RedirectToAction("Index", "Home"); } In my Views i have cshtml page with body and this part of code <form class="float_left" action="Controllers/AccountController" method="post"> <button class="btn btn-inverse" title="Log out" type="submit">Log Off</button> </form> And this doesn't work, anyone know what is problem

how to use factory/service for sharing information between multiple controllers in angularjs?

吃可爱长大的小学妹 提交于 2019-12-10 00:03:30
问题 Im trying to load a JSON when app starts, and spread the data between all my controllers. I know this is not very hard to do, but Im confused from all articles/answers I've read because they use different syntax than I do, can someone Please direct me on how to to that? Im currently making the controller make the $http.get : myApp = angular.module("myApp", []) myApp.controller "HomeCtrl", ($scope, $http, $routeParams) -> $http.get('gethome.php').success (data) -> $scope.home = data But I have

Rails 4 Runtime error in controller: Circular dependency detected while autoloading constant

痴心易碎 提交于 2019-12-08 16:15:15
问题 Let me know if I left anything out. I can't figure out why my views/references/ folder isn't accessible. neither new.html.erb nor index.html.erb is available. When I go to localhost:3000/references my error is: RuntimeError in ReferencesController#index Circular dependency detected while autoloading constant ReferencesController I believe this is setup, and It shouldn't be a Rails issue because my other controllers are working fine. My routes file has resources :references in it, my rake

Load Controller based on state params using Angular ui-router

安稳与你 提交于 2019-12-08 03:45:32
问题 I am trying to load a controller based on a stateparam to make it reusable .state("dashboard.item.detail", { url: "/detailId/:detailId/detailName/:detailName", views: { 'main@': { templateUrl: function ($stateParams){ //move this to a util function later var tempName = unescape($stateParams.detailName); tempName = tempName.replace(/\s/g, "-"); return '../partials/slides/' + tempName + '.html'; }, resolve: { DetailData: ['DetailService', function(DetailService){ return DetailService.getDetails

Ruby on rails controller code, needs refactor best way to approach for more dry?

天涯浪子 提交于 2019-12-08 01:46:47
问题 I have a welcome wizzard that builds a user profile when first login. Problem is it is quite messy implemented but I have tried to refactor it several times and rewrite it but cannot comeup with something better then below. In ideal world it would be all inside welcome_controller.rb but this have caused much headache so Now i rewrote the update method for profile_controller instead. Any thoughts on how to improve this make it more dry and clean? Would love to recieve some good input on this