scope

association data in rails model scope

谁都会走 提交于 2019-12-22 23:47:22
问题 I have a model named Post (blog post) and a model named Category . Each post belongs_to a category. Each category has an attribute named retainer that specifies the amount of time before a post "expires", so for example movies_category.retainer = 30.days What I'm trying to do is create a scope for Post that finds all of the posts which are "expired". So for example, assuming I were to hardcode the value of 30.days and it were to apply to all categories (therefore all posts), the scope would

How can I pass an NSString from one View Controller to another?

强颜欢笑 提交于 2019-12-22 18:51:57
问题 I made a very simple storyboard based project with two View Controllers. I want to simply access a string declared in VC1 from VC2. The second VC should then display the text in a textfield upon the press of a button. I do not want to use delegation , a separate class for global data or global variables and Extern . Instead, I read that it was easy to achieve variable sharing using a reference to one VC in the other. For my code shown below, XCode didn't complain, however my problem is this:

How can I pass an NSString from one View Controller to another?

青春壹個敷衍的年華 提交于 2019-12-22 18:51:12
问题 I made a very simple storyboard based project with two View Controllers. I want to simply access a string declared in VC1 from VC2. The second VC should then display the text in a textfield upon the press of a button. I do not want to use delegation , a separate class for global data or global variables and Extern . Instead, I read that it was easy to achieve variable sharing using a reference to one VC in the other. For my code shown below, XCode didn't complain, however my problem is this:

Variable scope (Python Newbie)

拥有回忆 提交于 2019-12-22 18:14:14
问题 I am using a .pop method on a Global list inside a function block, but the Global list is being updated outside the block. I thought that local variables can't modify Global variables. This should not work, but it does: import random PhraseBank = ['a','b','c','d'] def getPuzzle(secretphrase): phraseIndex = random.randint(0,len(PhraseBank)-1) secretphrase = PhraseBank.pop(phraseIndex) return secretphrase #Returns and item indexed from the PhraseBank while len(PhraseBank) != 0: secretphrase =

ExtJS - How to reference “self” in a custom function in a custom class?

别来无恙 提交于 2019-12-22 17:54:46
问题 How do I reference an instance of a custom class inside a custom function defined within the class? I've extended a class through ExtJS4's class extension "mechanism", and I've a custom event handler that will be called when something is triggered, and I want to collapse the Panel when something is fired. However, in the event handler of the Reactor class below, "this" references EventTriggerer (The firer of the event) instead of the instance of the Reactor. How do I reference the instance of

Angularjs - Restangular call inside factory/service

本小妞迷上赌 提交于 2019-12-22 17:18:41
问题 I am using factory as follows: var appModule = angular.module('appModule', ['ngRoute','restangular']); appModule .config(['$routeProvider', function($routeProvider) { $routeProvider .when('/home', { templateUrl: 'home.html', controller: 'ngHomeControl' }) .when('/contacts', { templateUrl: 'contacts.html', controller: 'ngContactControl' }); }]); appModule .factory('testFactory', function testFactory(Restangular) { return { getFriendList: function() { return Restangular .all('api/users

Javascript - value exists, then disappears, then appears again?

心已入冬 提交于 2019-12-22 12:32:09
问题 This is driving me nuts. I can't work it out stepping through with Firebug either. Can someone please explain what is going on here? Basically I have an incoming text file where each line contains a pipe-delimited record. I'm splitting these into an array of array of string for later use in an autocomplete textbox. The code is as follows: <script type="text/javascript"> $(function () { var rawData = new Array(); $.get("/sample.txt", function (data) { var raw = data.split('\n'); for (var i = 0

Have Python 2.7 functions remember value and not reference? Closure Weirdness

こ雲淡風輕ζ 提交于 2019-12-22 11:10:58
问题 I'm trying to return from a function a list of functions, each of which uses variables from the outside scope. This isn't working. Here's an example which demonstrates what's happening: a = [] for i in range(10): a.append(lambda x: x+i) a[1](1) # returns 10, where it seems it should return 2 Why is this happening, and how can I get around it in python 2.7 ? 回答1: The i refers to the same variable each time, so i is 9 in all of the lambdas because that's the value of i at the end of the loop.

Configuring lifetime scopes in autofac when used as ServiceStack's IoC

℡╲_俬逩灬. 提交于 2019-12-22 10:27:15
问题 I'm currently using AutoFac as the DI container for our ServiceStack web services app. I'm able to configure the wiring and everything, but after reading the section on Scopes, I'm at a loss at which scope would be best to use when registering my components. In our particular case, I think a PerHttpRequest scope would be OK since (please correct me if im wrong) I would want to dispose the dependencies as soon as the request ends. My question is, how do I set this up in the container? I can't

Performance differences between controller functions defined on `$scope` or `this` - AngulrJS

左心房为你撑大大i 提交于 2019-12-22 10:26:32
问题 In Angular, you can define methods in your controller by attaching them to $scope : $scope.myFunction = function () { ... } Of course, you can also attach them to this , which I've seen used for communicating between directives and a parent controller: /* within the controller */ this.myFunction = function () { ... } Are there performance differences between the two approaches due to Angular watching the values? Even if there aren't performance differences, it seems like a nice way of keeping