我想生成一个URL作为
/swimming/students/get_times/2013-01-01/2013-02-02
Run Code Online (Sandbox Code Playgroud)
从这条路线
get_class_swimming_students GET /swimming/students/get_times/:start_date/:end_date(.:format) swimming/students#get_times
Run Code Online (Sandbox Code Playgroud)
如何将参数传递给get_class_swimming_students_path?
这是我为这个简单任务的javascript代码:
如果元素不在数组中,请添加元素.
if(_.contains(this.types,type_id)){
var index = this.types.indexOf(type_id);
this.types.splice(index,1);
}
else{
this.types.push(type_id);
}
Run Code Online (Sandbox Code Playgroud)有没有更有效的方法来做到这一点?
我做了一些关于restful api身份验证的调查.大多数人都指出了Oauth2的resti api身份验证.我查看了一些资源,尤其是这个链接https://developers.google.com/accounts/docs/OAuth2.
在我看来,Oauth2是第三方应用程序访问谷歌/ Facebook(或其他数据提供商)中的用户数据.
我们的问题是我们拥有数据,我们不需要访问客户的任何第三方数据,我们的客户也不需要任何第三方数据.我们希望通过某种身份验证来保护我们的api.
对于我们的情况,我们的resti api身份验证的便捷技术是什么?我们会像这样暴露我们的api
https://ourdomain.com/api/<endpoint>
Run Code Online (Sandbox Code Playgroud)
我们的客户可以先访问网站注册https://ourdomain.com,他们应该能够从我们的网站获取clientId和clientKey以访问apis.我们的客户应该能够通过某种身份验证进行消费
我理解如何将一个javascript文件添加到rails资产管道.只需添加
//= require filename
Run Code Online (Sandbox Code Playgroud)
到application.js
但是如何在一个文件夹下包含许多javscripts文件
vendor/assets/javascripts/<js_library>
Run Code Online (Sandbox Code Playgroud)
或者我必须明确地列出它们?
我理解如何在rails控制台中运行一段简单的代码.说
Swimming::Student.create(:name="Jerry")
Run Code Online (Sandbox Code Playgroud)
我如何运行一大段代码(多行)
Swimming::Student.all.each{ |student|
student.attended = flase
student.save
}
Run Code Online (Sandbox Code Playgroud) 我正在使用restify建筑api,它很棒.但我需要在同一个应用程序中渲染一些网页.
我可以在一个应用程序中一起使用express和restify吗?
这是app.js中restify服务器的代码
var restify = require('restify');
var mongoose = require('mongoose');
var server = restify.createServer({
name : "api_app"
});
server.use(restify.queryParser());
server.use(restify.bodyParser());
server.use(restify.CORS());
mongoose.connect('mongodb://localhost/db_name');
server.get('/', routes.index);
server.post('/api_name', api.api_name);
server.listen(8000 ,"localhost", function(){
console.log('%s listening at %s ', server.name , server.url);
});
Run Code Online (Sandbox Code Playgroud)
如何在同一个app.js中创建快速服务器?
谢谢
Backbone的新手,请承担我不那么漂亮的主干javascript代码.
这是我的代码
var Schedule = Backbone.Model.extend({
initialize: function () {
console.log("initializing model");
}
});
var ScheduleCollection = Backbone.Collection.extend({
model: Schedule,
url: "<%=students_swimming_classschedules_path%>",
parse: function (resp) {
return resp;
},
});
var Schedules = Backbone.View.extend({
initialize: function () {
console.log("initializing view");
collection.on('add', this.render, this);
this.render();
},
render: function () {
for (var i = 0; i < collection.length; i++) {
s += "<tr><td>" + collection.models[i].get('account') + "</td><td>" + collection.models[i].get('status') + "</td></tr>";
}
this.$el.html(s);
},
})
var schedules = new Schedules({
el: …Run Code Online (Sandbox Code Playgroud) 我使用gem'twitter-bootstrap-rails'作为rails bootstrap
我在页面Rails代码上有一些链接
<td><%= link_to 'Destroy', swimming_classschedule, method: :delete, data: { confirm: 'Are you sure?' } %></td>
<li> <%= link_to "Logout", destroy_user_session_path, method: :delete, :class => 'navbar-link' %> </li>
Run Code Online (Sandbox Code Playgroud)
HTML代码:
<a href="/users/sign_out" class="navbar-link" data-method="delete" rel="nofollow">Logout</a>
<td><a href="/swimming/students/1" data-confirm="Are you sure?" data-method="delete" rel="nofollow">Destroy</a></td>
<td><a href="/swimming/students/3" data-confirm="Are you sure?" data-method="delete" rel="nofollow">Destroy</a></td>
Run Code Online (Sandbox Code Playgroud)
每当我点击删除学生时我都会退出.我完全糊涂了
这是我的路线设置
resources :messages do
collection do
get 'message'
end
end
Run Code Online (Sandbox Code Playgroud)
它工作正常,但我想在这条路线上添加一个参数
resources :messages do
collection do
get 'message/:username'
end
end
Run Code Online (Sandbox Code Playgroud)
我跑的时候出错了 rake routes
rake aborted!
missing :action
/home/li/data/git/projectname/config/routes.rb:5:in `block (4 levels) in <top (required)>'
/home/li/data/git/projectname/config/routes.rb:4:in `block (3 levels) in <top (required)>'
/home/li/data/git/projectname/config/routes.rb:3:in `block (2 levels) in <top (required)>'
/home/li/data/git/projectname/config/routes.rb:2:in `block in <top (required)>'
/home/li/data/git/projectname/config/routes.rb:1:in `<top (required)>'
/home/li/data/git/projectname/config/environment.rb:5:in `<top (required)>'
Tasks: TOP => routes => environment
(See full trace by running task with --trace)
Run Code Online (Sandbox Code Playgroud)
向此路线添加参数的正确方法是什么?
我可以很容易地测试用户是否具有某个角色
if user.has_role? :admin
Run Code Online (Sandbox Code Playgroud)
如何获取用户的角色名称?就像是
users = User.all
user.each{ |user|
puts user.role or users.role_name ?
}
Run Code Online (Sandbox Code Playgroud)
用户模型
class User < ActiveRecord::Base
rolify
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me ,:username,:first_name,:last_name
# attr_accessible :title, :body
end
Run Code Online (Sandbox Code Playgroud)
榜样
class Role < ActiveRecord::Base
has_and_belongs_to_many :users, :join_table => :users_roles
belongs_to :resource, :polymorphic => true …Run Code Online (Sandbox Code Playgroud)