关于sails 初学者常见问题汇总

一、安装时:

先装nodejs,成功标志 node -v

安装sails 全局安装 node install [email protected] -g 安装成功 sails -v

创建 项目 sails new projectname

安装grunt : npm install [email protected] --save-dev(在项目的目录中)

启动sails服务:sails lift

在启动时提示的错误,可以用 npm install 在当前的项目下进行安装。

在创建api时用命令:sails generate api book(在安装后很可能sails lift时会出现错误,此次的处理是npm install sails-config --save-dev

测试浏览:http://localhost:1337/user 创建http://localhost:1337/user/create?name=xy&password=fc12345

note:to avoid the migration warning from sails when generating the book api,add the following to config/env/development.js

models:{

migrate:"alter"

}

二、文件夹:

assets下可以放直接被url调用的网页,图片,js,等文件,url http://localhost:1337/在assets下的路径。

三、路由

config/routes.js

‘/‘:{view:‘homepage‘} localhost:1337

‘/about‘:{view:‘about‘} localhost:1337/about  在views下创建 about.ejs

路由蓝图包括以下三种:

restful路由

These routes always have the path of /:modelName or /:modelName/:id

and send the request to the appropriate action by using the HTTP "verb".Middleware policies should be used in a production environment to protect these routes fromuauthorized access.

shortcut路由

these routes only respod to "get" requests and determine which action to send the request to by decoding the path.An example path would look like

/:modelName/<action> and data would be passed to the controller action using query parameters. While great for development work o a prototype,these routes should be disabled in production.

action路由

Thes routes create shortcut routes for custom actions tat don‘t come for free as part of the restful routes.So for any custom action on a controller,a corresponding path followingthe format /:controllerName/:actionName whill respond to get requests and send the request to the controller.

Blueprit Actions

The Blueprint API creates a number of generic actions tohandleall of the standard behaviour of a restful JSON API to match the BluePrint routes.The following default controller actions,which can be overridden,are provided by the Blueprint api:

find findOne create update destory populate add remove

如何使用 http verb?

‘get /posts‘:{

controller:‘postsController‘,

actio:‘list‘

}

这个配置告诉应用对get 的请求做出回应,在url处理方式为postscontroller下的list操作。

‘put  /posts/:id‘:{

controller: ‘postsController‘,

action:‘update‘

}

这个配置对put请求做出回应,更新一个已存在的用户,其中id为参数,update是postsController中的一个操作。

如何更改模板?

1.用jade 代替 Ejs

npm install jade --save

更改config/views.js文件:

module.exports.views={

engine:‘jade‘,

layout:fasle,这个只有ejs支持,所以换成jade后,要把layout设为false;

locals:{//any options you would like to pass to the jade parser}

}

最后从package.json中移走ejs;

样式文件的替换用sass 替换 less

1.把grunt-contrib-less从age.json中移走,npm install grunt-contrib-sass --save

2.改变所有Grunt task 中的less 引用为 sass.(需要改变的有如下文件)

tasks/cofig/copy.js

tasks/register/compileAssets.js

tasks/register/syncAssets.js

其实如果是新项目了只需更改 tasks/importer.less为importer.sass,其它的都由Sass自动适配。

用postgres 代替LocalDB

waterline (与许多流行的数据库一起工作)(如:Postgresql,MongoDB,Redis.)

时间: 2024-08-03 00:05:10

关于sails 初学者常见问题汇总的相关文章

ASP.NET MVC 应用程序初学者常见问题汇总

Q: 如何为Html.TextBoxFor控件添加多个属性? A: @Html.TextBoxFor(m => m.Email, new Dictionary<string, object>() { {"class", "input-material" }, {"data-msg", "Please enter your username" },{ "required", "tr

Google AdMob 常见问题汇总

AdMob 常见问题汇总 五 09 **** 客服相关 **** 1. 请问 AdMob 有没有客服可以提供如帐号被封.付款信息.申诉渠道等的咨询? 有的:有关 AdMob 的问题,可以访问我们的帮助中心: http://support.google.com/admob/?hl=zh-Hans&hlrm=en. 如果没有找到相应解答,也可以通过 @AdMob开发者官方微博 与我们进行互动: http://www.weibo.com/googleAdMob. **** 使用 AdMob *****

destoon入门实例与常见问题汇总

destoon入门实例与常见问题 收集了一些destoon入门实例与常见问题,大家做个参考.转自:http://blog.csdn.net/vip_linux/article/details/37833963 链接如下: destoon忘记后台密码怎么办?destoon找回管理员密码 忘记destoon管理员后台账号密码怎么办?解决方法 destoon如何实现调用自增数字从1开始 destoon底部添加你是第几位访问者 destoon调用热门关键字的例子 destoon首页怎么调用求购供应信息的

IDE常见问题汇总

1.Oracle10gForVistaX64下载地址:http://download.oracle.com/otn/nt/oracle10g/10204/10204_vista_w2k8_x64_production_db.zip 2.Oracle 10g x64 for Vista 在Win7x64下安装需要修改三个文件:(1).\10204_vista_w2k8_x64_production_db\database\stage\prereq\db\refhost.xml (2).\10204

【初学者常见问题】Java中关于static的谜团

static是Java中的一个关键字,它能够声明在方法中,如public static void test(),这就是一个静态方法,他可以通过类名.方法名来调用,当然也可以给变量声明,如public static int a = 10; 它就是一个静态变量,也可以通过上述类名.方法名来调用. 以前写过一篇<反思--基础很重要>的文章,基础的扎实往往在后面的道路中会如鱼得水.那次只给出题目,是一道在笔试过程中经常出现的题目,这几天读<深入理解java虚拟机>这本书又有了对这段代码深入

[转]H5项目常见问题汇总及解决方案

html { line-height: 1.6 } body { font-family: -apple-system-font, "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif; background-color: #f3f3f3; line-height: inherit } body.rich_media

CentOS安装Oracle数据库详细介绍及常见问题汇总

一.安装前准备 1.软件硬件要求 操作系统:CentOS 6.4(32bit)Oracle数据库版本:Oracle 10g(10201_database_linux32.zip)最小内存:1G(检查命令:#grep MemTotal /proc/meminfo)最小Swap:2G(检查命令:#grep SwapTotal /proc/meminfo) 2.安装依赖包 # rpm -q binutils compat-libstdc++-33 compat-libstdc++-33.i686 el

mysql几个常见问题汇总

mysql几个常见问题汇总 一. mysql下的清屏命令 \! clear:Ctrl+shift+L:Ctrl+L Linux下的清屏命令 Clear ; Ctrl+L; Shift+ctrl+L 二. 查看mysql版本的四种方法 1:在终端下:mysql -V. 以下是代码片段: [[email protected] ~]$ mysql -V mysql Ver 14.7 Distrib 4.1.10a, for redhat-linux-gnu (i686) 2:在mysql中:mysql

SVN集中式版本控制器的安装、使用与常见问题汇总

SVN是Subversion的简称,是一个开放源代码的版本控制系统,它采用了分支管理系统,集中式版本控制器 官方网站:https://www.visualsvn.com/ 下载右边的服务器端,左边的客户端收费,我们使用TortoiseSVN替代他即可 TortoiseSVN:TortoiseSVN 是 Subversion 版本控制系统的一个免费开源客户端,可以超越时间的管理文件和目录.文件保存在中央版本库,除了能记住文件和目录的每次修改以外,版本库非常像普通的文件服务器.你可以将文件恢复到过去