sails.js

Using TypeScript with Sails

自作多情 提交于 2019-12-04 18:05:27
问题 Is anyone using TypeScript with Sails? If so, what are you using for external declarations? I am in the middle of a Sails application project and learned about TypeScript. I am trying to determine if TypeScript is something I should pursue for this project. Any info will be appreciated. Thanks. 回答1: from : https://github.com/balderdashy/sails Sails is built with node connect express and socket.io . This means that definition files for these libraries are what you need. All of these are

Sails.js - passing data to a view

我与影子孤独终老i 提交于 2019-12-04 17:56:17
问题 I've recently started learning how to use Sails.js and I came across a small issue. I have a model called Applicant, as follows: module.exports = { attributes: { name: { type: 'STRING', required: true }, email: { type: 'STRING', required: true } } }; I have built the index action to return all the instances of the Applicant model: module.exports = { index: function(req, res) { Applicant.findAll().done(function(err, applicants) { res.view({ apps: applicants }); }); } }; And this is the view

How can I select different databases for a model based on request parameters in Sails.js?

為{幸葍}努か 提交于 2019-12-04 17:17:58
I have an application that I am considering porting to Sails.JS. One of the big issues I am having is supporting the per-request database selection that we have right now. Our app creates/uses a different database for each customer that we have and we select the database based on the request. How could I achieve that in Sails.JS? Could I write a Express middleware that would do this on a per request basis? 来源: https://stackoverflow.com/questions/26930432/how-can-i-select-different-databases-for-a-model-based-on-request-parameters-in

Waterline default query condition

断了今生、忘了曾经 提交于 2019-12-04 16:56:49
How can I set the default where/sort condition in my SailsJS waterline model? In Rails I would use default scope . Sails doesn't support default criteria on a per-model basis, but if you're using blueprint routes you can set default criteria for the route by overriding in your config/routes.js file, for example: "GET /user": { controller: 'user', action: 'find', where: {'deleted': false}, sort: 'age DESC' } This will work even if you don't have a find action defined in your UserController.js file, because the blueprint is added for you by default. 来源: https://stackoverflow.com/questions

Sailsjs/waterline specify number of decimal places in model

瘦欲@ 提交于 2019-12-04 14:52:48
How do I tell my sails model that I want some specific number decimal places for a type: 'float' attribute? Like decimalPlaces: 4 or something of that ilk? The problem is that when i post a value to this entry, the value on disk is truncated to the .00 (hundreds) place. Say I want: 3243.2352362 to be stored just as it is. Currently this is transformed into 3243.24 If it matters I'm using the sails-mysql adapter. Martin Malinda types: { decimal2: function(number){ return ((number *100)%1 === 0); } }, attributes: { myNumber: { type: 'float', decimal2: true } } This is for 2 decimal places though

Show image immediately after upload in sailsjs

送分小仙女□ 提交于 2019-12-04 14:22:37
I have form with upload field. After searching for a while, I just put uploaded files to folder ./assets/posts and it worked correctly. In my app, when submit done, it should be reload current url and show new uploaded image. But it didn't. My sails app use linker to manage assets. So after 3 or 4 times I try to reload the page, image is showed. How to show image immediately when I submit done? Thanks a lot! bredikhin Sails uses assets folder to store mainly the assets that are supposed to be precompiled and/or published, e.g. scripts, styles and minor images (icons, etc.). For images it means

How can I set different <title> values for each template in ejs?

寵の児 提交于 2019-12-04 13:40:45
I am using Sails.js and it comes with ejs-templates. There is a default view called layout.ejs which is always including the body parts from other templates. The title element is defined in the layout.ejs and is therefore always the same. Due to SEO I would like to change the title depending on the view that is included. Is there some way of knowing which view is actually called from Sails, in the .ejs file? Update the <title> tag of your layout.ejs to <title><%= title %></title> and send a title value from your controller along with the other data, like res.view('viewname', { title:

Sails: 404 pages won't use the default layout?

删除回忆录丶 提交于 2019-12-04 12:32:57
In sails.js, all files that are in the views folder use layout.ejs as their template. Error pages like 404.ejs won't use layout.ejs for some reason. I couldn't find any setting for that, can I change it? Thanks! A link to the repository, if needed: http://github.com/ronenteva/MySkills Sails v0.10.x uses the notFound response to serve the 404 page, equivalent to calling res.notFound() in a controller action. A default response handler is provided for you in api/responses/notFound.js , but you can customize it to do anything you like, including using res.view() to serve the 404 page with a

SailsJS, SocketIO, not getting messages

我的未来我决定 提交于 2019-12-04 11:56:47
I have a simple login script. I created a method in the SessionController called create to handle logins. I do all the needed validation and then set the user as active and save them. I also use User.publishUpdate() to send the message back to the client. The problem is that I recieve no messages at all. When the page is loaded I call User.subscribe(req.socket, users); for all users so they are all subscribed. Not really sure why the messages aren't sent. I am using sails 0.10.0. This is the subscribe method which is called on page load: User.find({}).exec(function (error, users) { if (error)

Sails js 9.4 - assets not being copied

余生长醉 提交于 2019-12-04 11:34:53
First sails didn't create .tmp/public, so i did it manually. But it also doesn't copy stuff from my assets folder to my public folder. Can someone explain why that is? # At that time, the answers i got weren't helping, I've updated to 9.8 now, and i don't seem to have any problem. # I had this same issue. When running sails lift the .tmp folder wasn't created. What finally worked for me was installing Grunt locally in the root folder of my sails app. So just run npm install grunt in your sails app folder. Having Grunt installed globally with the -g flag was apparently not enough. After the