Wednesday, April 18, 2012

Error: Failed to lookup view in Express

Note: my auto answer at end of the post



I'm trying to make a better experience of nodeJS and i don't really like to get all the script in one file.



so, following a post here i use this structure



./
config/
enviroment.js
routes.js
public/
css/
styles.css
images
views
index
index.jade
section
index.jade
layout.jade
app.js


My files are right now:



app.js



var express = require('express');
var app = module.exports = express.createServer();

require('./config/enviroment.js')(app, express);
require('./config/routes.js')(app);

app.listen(3000);


enviroment.js



module.exports = function(app, express) {
app.configure(function() {
app.use(express.logger());
app.use(express.static(__dirname + '/public'));
app.set('views', __dirname + '/views');
app.set('view engine', 'jade'); //extension of views

});

//development configuration
app.configure('development', function() {
app.use(express.errorHandler({
dumpExceptions: true,
showStack: true
}));
});

//production configuration
app.configure('production', function() {
app.use(express.errorHandler());
});

};


routes.js



module.exports = function(app) {

app.get(['/','/index', '/inicio'], function(req, res) {
res.render('index/index');
});

app.get('/test', function(req, res) {
//res.render('index/index');
});

};


layout.jade



!!! 5
html
head
link(rel='stylesheet', href='/css/style.css')
title Express + Jade
body
#main
h1 Content goes here
#container!= body


index/index.jade



h1 algoa


The error i get is:




Error: Failed to lookup view "index/index"
at Function.render (c:\xampp\htdocs\nodejs\buses\node_modules\express\lib\application.js:495:17)
at render (c:\xampp\htdocs\nodejs\buses\node_modules\express\lib\response.js:614:9)
at ServerResponse.render (c:\xampp\htdocs\nodejs\buses\node_modules\express\lib\response.js:638:5)
at c:\xampp\htdocs\nodejs\buses\config\routes.js:4:7
at callbacks (c:\xampp\htdocs\nodejs\buses\node_modules\express\lib\router\index.js:177:11)
at param (c:\xampp\htdocs\nodejs\buses\node_modules\express\lib\router\index.js:151:11)
at pass (c:\xampp\htdocs\nodejs\buses\node_modules\express\lib\router\index.js:158:5)
at Router._dispatch (c:\xampp\htdocs\nodejs\buses\node_modules\express\lib\router\index.js:185:4)
at Object.router [as handle] (c:\xampp\htdocs\nodejs\buses\node_modules\express\lib\router\index.js:45:10)
at next (c:\xampp\htdocs\nodejs\buses\node_modules\express\node_modules\connect\lib\proto.js:191:15)




But i don't really know what is the problem...



I'm starting thinking is because the modules exports...



Answer:
Far away the unique solution i found is to change the place i defined app.set('views') and views engine



I moved it to the app.js and now is working well.



var express = require('express');
var app = module.exports = express.createServer();


require('./config/enviroment.js')(app, express);

app.set('views', __dirname + '/views');
app.set('view engine', 'jade');

require('./config/routes.js')(app);

app.listen(3000);


I don't really understand the logic behind this but i gonna supose it have one.





Asp.net: how to compare DataBinder.Eval with a member variable?

I am trying to do this in a repeater:



<%# Iif((int)DataBinder.Eval(Container.DataItem, "Id") == SelectedJobDefId, "blue", "red")%>


Problem is that the member property only evaluates if this syntax is used:



<%= SelectedJobDefId %>


DataBinder.Eval() only works if the hash symbol is used.



As a test, I tried this:



  <%= SelectedJobDefId %>
<%# DataBinder.Eval(Container.DataItem, "Id") + " " + SelectedJobDefId %>


The first SelectedJobDefId stays correct as I switch rows (LinkButton event).
The DataBinder part is correct for each row.
The 2nd output of SelectedJobDefId is always "1".



How can I compare these two values?





Automating C++ unit test runs for WinRT

Since running Metro apps headlessly is still a gray area: Running a metro app headlessly, I've recently decided to add a native unit test project to my Windows Metro app in hopes that I can find a way to run these unit tests in an automated fashion on the build server. Basically, I'm looking for something similar to MSTest.exe - a utility which is great for running tests from batch files and/or scripts.



In fact, I've tried using the new version of MSTest.exe that comes with VS11 on a generated test .dll, but it fails with the error:



"Unable to load the test container 'test.dll' or one of its dependencies... Error details: Could not load file or assembly file://test.dll' or one of its dependencies. The Module was expected to contain an assembly manifest."



Does MSTest.exe work with test containers that contain WinRT code? If not, is there a utility that will do what I want?





What's the best way to cast a custom Class in PHP

I know off the bat some of you will assume Interface or Abstract, but that only handles SOME of the situations. Here's an example where they break.



Assume we have classes that implement the same interface and extend the same base



  class car extends fourwheeler implements ipaygas{       

var tank1;

//interface
public function payGas($amount){}

}

class sportcar extends fourwheeler implements ipaygas{

var tank1;
var tank2;

//interface
public function payGas($amount){}

}

interface ipaygas{

function payGas($amount);
}


In some situations an interface is all you need as you may only want to execute 'payGas()'. But what do you do when you have conditions to be met.



Example, what if - before paying gas you need to (1) check the car type, (2) use premium gas for the sports car, and (3) fill the second tank of the sports car.



THIS IS WHAT I WANT TO DO BUT CANNOT



   function pumpAndPay((iPayGas) $car){
if(gettype($car) == "car"){
fillTank($car,(car) $car->tank1);
}else{
fillTank($car,(sportscar) $car->tank1);
fillTank($car,(sportscar) $car->tank2);
}
}


How can I do this with real type casting? Is it possible in PHP?





Play sound on internal speakers and possibility to use old xp api function?

After the release of windows vista the Windows Function Beep plays a beep on your connected speakers instead of the internal one.



Is there anyway to access the old function? Would it be possible by getting hold in an older windows api? Or is there any other way i can make this possible? If so i would like the ability to set both the frequency and duration.



I should mention that I´m actually targeting the windows xp platform.





How to disable an eventhandler when another is getting called

I have two event listeners on one input field. One gets called on change and one when you click on an autocomplete dropdown from google. My problem is when you click on such a autocompletion both handlers get called and make the request to the google api.



I tried to bind the onchange event and unbind it when the google autocomplete ajax call get fired, but the onchange event is executed first. So it will not get unbinded.
So, is there any possibility to detect if the user made the input manually or via autosugesstion? I want to execute the "requestlocation" function only when the user makes a manually input and doesn't use the autocomplete dropdown.
I tried it with some other eventhandler like "focus-out", but without success.



This line makes the bind:



autoCompleteInput.on "change", requestlocation


This is the function which get called:



requestlocation = () ->
address = autoCompleteInput.val()
geocoder = new google.maps.Geocoder()
geocoder.geocode
address: address, (results, status) ->
if status is google.maps.GeocoderStatus.OK

if results[0].address_components.length > 1
city = results[0].address_components[0].long_name
country = results[0].address_components[results[0].address_components.length-1].long_name
setHiddenFields results[0].geometry.location.lat(), results[0].geometry.location.lng(), city, country
autoCompleteInput.val(city+", "+country)
else
city = null
country = results[0].address_components[0].long_name
setHiddenFields results[0].geometry.location.lat(), results[0].geometry.location.lng(), city, country
autoCompleteInput.val(country)
setMarker new google.maps.LatLng(latInput.val(), lngInput.val())
else
console.log "Geocode was not successful for the following reason: " + status


This is the code where the autocomplete handler makes the request:



google.maps.event.addListener autocomplete, 'place_changed', ->
autoCompleteInput.off "change", requestlocation

place = autocomplete.getPlace()

if !!place.geometry
autoCompleteInput.attr "data-valid", "true"
setMarker place.geometry.location
address = place.address_components
if address.length > 1
setHiddenFields place.geometry.location.lat(), place.geometry.location.lng(), address[0].long_name, address[address.length-1].long_name
else
setHiddenFields place.geometry.location.lat(), place.geometry.location.lng(), null, address[0].long_name
else
autoCompleteInput.attr "data-valid", "false"

autoCompleteInput.on "change", requestlocation


Thanks for any answers!





Function/Library like preg_match_all(PHP) in iPhone programming

I' m searching function that will works like preg_match_all (or similar) from for example PHP.



I want give a pattern and my NSData object(with HTML content) then get all results that fits to pattern.



I' m programming iOS 5. Is there any library or function to do this ?