我们使用简单的Ajax更新在Rails中实现了一个简单的聊天室功能.现在,在每个聊天室中,消息属于特定用户.我们想要显示用户列表(类似用户在场).请提出建议.我们没有使用Jabber,XMPP等.
聊天室模型是:
class ChatRoom < ActiveRecord::Base
validates_presence_of :title
has_many :messages,:foreign_key=> "chat_room_id"
has_many :stories,:foreign_key=>"chat_room_id"
has_many :topics,:foreign_key=>"chat_room_id"
end
Run Code Online (Sandbox Code Playgroud)
消息是每个用户发送的聊天记录.
消息模型是:
class Message < ActiveRecord::Base
belongs_to :user
end
Run Code Online (Sandbox Code Playgroud)
USer模型是:
class User < ActiveRecord::Base
acts_as_authentic :crypto_provider => Authlogic::CryptoProviders::BCrypt
validates_presence_of :nick
validates_uniqueness_of :nick
has_many :questions
end
Run Code Online (Sandbox Code Playgroud)
请提出建议
我通过CIPL.in使用共享主机.他们使用cpanel.我正在尝试在我的网站上部署ZEND应用.但是它不断给出错误.
An error occurred
Application error
Exception information:
Message: The PDO extension is required for this adapter but the extension is not loaded
Stack trace:
#0 /home/cubeeeco/worminc/library/Zend/Db/Adapter/Abstract.php(770): Zend_Db_Adapter_Pdo_Abstract->_connect()
#1 /home/cubeeeco/worminc/library/Zend/Db/Adapter/Abstract.php(840): Zend_Db_Adapter_Abstract->quote('windchimes', NULL)
#2 /home/cubeeeco/worminc/library/Zend/Auth/Adapter/DbTable.php(354): Zend_Db_Adapter_Abstract->quoteInto('`password` = MD...', 'windchimes')
#3 /home/cubeeeco/worminc/library/Zend/Auth/Adapter/DbTable.php(285): Zend_Auth_Adapter_DbTable->_authenticateCreateSelect()
#4 /home/cubeeeco/worminc/library/Zend/Auth.php(117): Zend_Auth_Adapter_DbTable->authenticate()
#5 /home/cubeeeco/worminc/application/controllers/LoginController.php(117): Zend_Auth->authenticate(Object(Zend_Auth_Adapter_DbTable))
#6 /home/cubeeeco/worminc/library/Zend/Controller/Action.php(503): LoginController->processAction()
#7 /home/cubeeeco/worminc/library/Zend/Controller/Dispatcher/Standard.php(285): Zend_Controller_Action->dispatch('processAction')
#8 /home/cubeeeco/worminc/library/Zend/Controller/Front.php(934): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#9 /home/cubeeeco/public_html/worm/index.php(47): Zend_Controller_Front->dispatch()
#10 {main}
Run Code Online (Sandbox Code Playgroud)
当我尝试打印phpinfo时,我得到:
System Linux bear.dnsracks.com 2.6.18-92.1.13.el5PAE #1 SMP Wed Sep 24 20:07:49 EDT 2008 i686
Build Date Jun 8 …Run Code Online (Sandbox Code Playgroud) 我有一些格式的数据:
VAR1 VAR2 Score1 Score2 Score3
A B 1 2 3
Run Code Online (Sandbox Code Playgroud)
我需要将其转换为格式
VAR1 VAR2 VarName Value
A B Score1 1
A B Score2 2
A B Score3 3
Run Code Online (Sandbox Code Playgroud)
如何在 SQL 中执行此操作?
我有一个故事文本字段,并希望在快照页面中显示前几行 - 比如该字段的前50个单词.我怎么能在Ruby(在Rails上)做到这一点?
我试图在customer表中实现NOT NULL约束,该表创建为:
CREATE TABLE CUSTOMER(
cust_id INT(5) NOT NULL AUTO_INCREMENT,
PRIMARY KEY(cust_id),
first_name VARCHAR(25) NOT NULL,
last_name VARCHAR(25) NOT NULL,
email VARCHAR(25) NOT NULL,
password VARCHAR(25) NOT NULL,
gender VARCHAR(1) NOT NULL,
city VARCHAR(25) NOT NULL,
dob DATE NOT NULL,
pin INT NOT NULL);
Run Code Online (Sandbox Code Playgroud)
从表单中传递值后,我将其插入为:
$sql= "INSERT INTO customer(first_name,last_name,email,password,gender,city,dob,pin) VALUES('$first_name','$last_name','$email_add','$password','$gender','$city','$DOB','$pin')";
Run Code Online (Sandbox Code Playgroud)
但是,如果我传递字段的空白值,Mysql似乎插入它们?可能有什么问题?
我想像在Rails gudes网站(http://guides.rubyonrails.org/)中使用的那个或者在BaseCamp.CAn中使用的那些,使用Rails表单助手完成一个巨型工作?
我被问到这个问题而无法得出答案.
有没有办法在表格的第一行和第一列找到条目?
(在矩阵表示法中,那将是[1,1]th位置)
我无法应用ucminf函数来最小化我在R中的成本函数.
这是我的成本函数:
costfunction <- function(X,y,theta){
m <- length(y);
J = 1/m * ((-t(y)%*%log(sigmoid(as.matrix(X)%*%as.matrix(theta)))) - ((1-t(y))%*%log(1-sigmoid(as.matrix(X)%*%as.matrix(theta)))))
}
Run Code Online (Sandbox Code Playgroud)
这是我的sigmoid函数:
sigmoid <- function(t){
g = 1./(1+exp(-t))
}
Run Code Online (Sandbox Code Playgroud)
这是我的渐变功能:
gradfunction <- function(X,y,theta){
grad = 1/ m * t(X) %*% (sigmoid(as.matrix(X) %*% as.matrix(theta) - y));
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试执行以下操作:
library("ucminf")
data <- read.csv("ex2data1.txt",header=FALSE)
X <<- data[,c(1,2)]
y <<- data[,3]
qplot(X[,1],X[,2],colour=factor(y))
m <- dim(X)[1]
n <- dim(X)[2]
X <- cbind(1,X)
initial_theta <<- matrix(0,nrow=n+1,ncol=1)
cost <- costfunction(X,y,initial_theta)
grad <- gradfunction(X,y,initial_theta)
Run Code Online (Sandbox Code Playgroud)
这是我想要调用ucminf以找到theta的最低成本和值的地方.我不知道该怎么做.
我已经使用Ruby on Rails做了一些工作但是仍然不习惯从头开始编写Rails应用程序.我的问题是,当我尝试从头开始编写应用程序时,我无法理解如何使正确的模型运行.我认为看到一个完整的现有应用程序的代码可能会有所帮助,但我不确定.应该怎样对待我?