我是Ubuntu(Linux tbh)的新手.我遇到了启动MongoDB服务的问题.我想使用Ruby on Rails和MongoDB创建Web应用程序,但是mongo似乎无法启动.
我在Ubuntu上跟踪了这个MongoDB安装,所有的安装都没有问题,直到我到达sudo service mongod start
mongod.log
2016-01-01T10:58:15.545+0000 I CONTROL ***** SERVER RESTARTED *****
2016-01-01T10:58:15.548+0000 I CONTROL [initandlisten] MongoDB starting : pid=3868 port=27017 dbpath=/var/lib/mongodb 64-bit host=damian-CX61-0NC-CX61-0ND-CX61-0NF-CX61-0NE
2016-01-01T10:58:15.548+0000 I CONTROL [initandlisten] db version v3.0.8
2016-01-01T10:58:15.548+0000 I CONTROL [initandlisten] git version: 83d8cc25e00e42856924d84e220fbe4a839e605d
2016-01-01T10:58:15.548+0000 I CONTROL [initandlisten] build info: Linux ip-10-187-89-126 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49
2016-01-01T10:58:15.548+0000 I CONTROL [initandlisten] allocator: tcmalloc
2016-01-01T10:58:15.548+0000 I CONTROL [initandlisten] options: { config: "/etc/mongod.conf", …Run Code Online (Sandbox Code Playgroud) 我对 React 数组有点迷失了。我想要做的是拥有组件(文章)数组,并且在该数组中我想要拥有标题和内容。
我想要对该数组执行的操作是添加、删除并将其显示在我的页面上。
那么我做错了什么?另外这个动作到底叫什么?
代码来自ReactJS 演示并由我修改了一些。
var ReactDOM = require('react-dom');
var React = require('react');
// Articles page
const Articles = React.createClass({
getInitialState() {
return {article: [
{'title': 'hello', 'content': 'hello hello'},
{'title': 'hello1', 'content': 'hello hello1'},
{'title': 'hello2', 'content': 'hello hello2'},
{'title': 'hello3', 'content': 'hello hello3'}
]};
},
onAdd() {
const newArticle =
this.state.article.concat([window.prompt('Enter article')]);
this.setState({article: newArticle});
},
onRemove(i) {
const newArticle = this.state.article;
newArticle.splice(i, 1);
this.setState({article: newArticle});
},
render() {
const article = this.state.article.map((article, i) => …Run Code Online (Sandbox Code Playgroud) 我正在制作一个网络应用程序(聊天之类的东西),因为昨天我从 Pundit (因为它太难了)切换到 Cancancan (它对我来说看起来更好)。
我正在尝试使一些简单的工作变得简单,例如显示所有文章及其选项(显示、编辑、销毁),然后对其设置权限,以便创建此类文章的唯一用户将能够编辑或销毁它。
问题是我不明白它是如何完全实施的。谷歌缺乏示例,而且大多数示例都已过时。
这是我所拥有的:
ability.rb - 我不知道这是否正确
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new # guest user (not logged in)
if user.admin?
can :manage, :all
else
can :read, :all
end
can :read, :articles
can :create, :articles
end
end
Run Code Online (Sandbox Code Playgroud)
User.rb(设计)
class User
include Mongoid::Document
has_many :articles
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
## Database authenticatable
field :username, type: String, …Run Code Online (Sandbox Code Playgroud)