I have an issue with pluralization in Mongoose that Im sure is easy to fix but I cant figure it out myself.
So, I have a Model called "Eventinstance" and a controller called "eventinstances". Either mongoose or angular is doing something with the pluralization on this.
When I have link like this (via Angular in a view):
(<a href="" ng-click="remove(eventinstance)" >Remove</a>)
It does a DELETE to: http://localhost.com/eventinstances?eventinstancesId=5278fb0792b06cad0d000002 ---404 (Not Found)
When it should go to: http://localhost.com/eventinstances/5278fb0792b06cad0d000002
What do you think could be causing this?
Many thanks,
kseudo
This is wrong declaration of your resource in Angular.
Declare it:
$resource('http://localhost.com/eventinstances/:id', {id: '#eventinstancesId'});
not as
$resource('http://localhost.com/eventinstances/');
If you omit :id in your declaration, eventinstancesId is appended as parameter after ? in your URL.
More info: $resource
Related
I have faced upon a problem which may sound weird but lot of people must be dealing with.
I have defined two routes in my routes.js file.
Route1
router.route('/atpages/:query')
.get(app.oauth.authorise(), atpagesController.getAtpagesByIdOrName);
Route2
router.route('/atpages/match')
.get(app.oauth.authorise(), atpagesController.matchAtpagesByUrl);
Both the routes are supposed to call different functions in controller, but the issue is whenever i hit Route2 automatically Route1 is being called. I know the issue that it is considering match as a query, my problem is that i need the routes to hit different questions without redefining their endpoints.
What i want is route should remain the same as they are but they should hit respective functions only.
TIA.
Thanks, i resolved the issue.
In my function for route1 i have made a check that if i get query params as match, i am calling the function corresponding to route2.
I am using Express with Node and I have a requirement in which the user can request the URL as: http://myhost/api/add?mid="mid01"/userID
and I tried this
app.get('/api/:myMedia/:id', function (req, res){
...
})
and tried these req.query for getting mid01 and it didn't work.
I want to have req.params.id and req.query together. How can I handle this?
If your requirement really is http://myhost/api/add?mid="mid01"/userID, it might be a good idea to change that requirement, because it seems really not the right way to do something
But if you really want to do that you should declare your route like app.get('/api/add', ...)
Then with req.query.mid you can get your query value which is "mid01"/userID
Finaly it's up to you to parse that query value to do what you want
But you should not use URL like that, if possible try to use URL in a more standard way, http://myhost/api/add/userID?mid=mid01 or http://myhost/api/add?mid=mid01&path=/userID
To chain requests, use &. http://myhost/api/add?foo1="bar1"&foo2="bar2". This way both of the queries will show up.
I've got a node app using the express server and I'm struggling with the routing. 'Browse' is the function and 'type', 'subtype' and 'name' are variables. If I have a route like:
/browse/type/subtype/name
then I can pick that up with:
/browse/:type/:subtype/:name
...so the vars show up separately in the req.params object. Sometimes, however, not all of the vars will appear, so you may get a url like:
/browse/cars
I want a route that catches them all, but if I use a wildcard then req.params will not pick them up as separate parameters. My best guess was something like:
/browse(/:type)?(/:subtype)?(/:name)?
Anyone know how this should be done?
/browse/:type?/:subtype?/:name? should work
I just started trying out Derbyjs, and I already ran into a problem. I can't find any support for this error, and most likely is some dumb mistake i'm making.
I'm trying to render a view, following the example from the www.derbyjs.com documentation.
My app is as simple as this:
var app = require('derby').createApp(module);
app.get('/', function (page, model) {
page.render('home');
});
My views are composed by two files.
"index.html"
<import: src="home">
<Body:>
Default page content
"home.html"
<Body:>
Welcome to the home page
I get the following error whenever the page is rendered:
TEMPLATE ERROR
Error: Template import of 'home'... ...can't contain content
As you can see, it is a very simple example. What am I missing?
I get that error even if I have the "home.html" file empty.
Well, I got the answer from one of the developers.
It seems like there was a subtle bug in the Template Parser that probably has already been fixed.
Having a whitespace or linebreak in front of
<import: src="home">
was causing the parser to raise the error. Writing
<import: src="home"><Body:>
solved the issue.
I've tried all the permutations I can think of but alas with no success.
I am trying to set an id dynamically in a jade template.
#{page.name}(data-role= 'page', data-theme= 'c', data-url='#{"#"+page.name}')
I wondering if it's actually possible.
Anyone know how to do this?
If some one knows, please help me out - before all my hair falls out :(
For anyone looking for the answer to this:
Answered kindly by TJ the developer of express.
div(id=myPassedId),
div##{myPassedID}( isn't supported because it would be super ugly
The suggestions here did not work in my scenario...
The format that worked for me:
x-task-id!="<%= id %>"
Ugly, but functional.
Nowadays you can also use a template literal:
- const page = { name: 'foo' }
#{page.name}(data-role="page" data-theme="c" data-url=`#${page.name}`)
Output (using Pug 2.0.4):
<foo data-role="page" data-theme="c" data-url="#foo"></foo>