我有一些我正在修改的继承代码.但是,我看到一些奇怪的东西(对我来说).
我看到一些像这样的代码:
::User.find_by_email(params[:user][:email]).update_attributes(:mag => 1)
Run Code Online (Sandbox Code Playgroud)
我从未见过这样的东西(我是Ruby on Rails的新手).这是做什么的,为什么我的User.find_by_email(params[:user][:email]).update_attributes(:mag => 1)
工作没有?错误说明了User
常量.
如果有帮助,我正在使用Rails 2.3.5.
我一直在玩两个不错的基于PHP的ORM.OutletORM和phpDataMapper.
有人有经验吗?一个优于另一个的任何优点.问一个拥有更大用户群的问题也是一个很好的问题.
我正在使用CodeIgniter构建一个站点.这是我自己构建的第一个与数据库交互的站点.我在这个项目中使用MySQL.如何在将数据保存到数据库之前判断数据是否需要转义?
我开始使用基于CI 2.0 Reactor存储库的新CI项目.因为CI2代码仍在变化,我想保持代码新鲜,问题是如何(使用Git).
对于非CI人员,CI2项目的基本结构如下所示:
system/
application/
index.php
...
Run Code Online (Sandbox Code Playgroud)
系统目录包含框架,index.php执行引导和应用程序包含我的项目.理想情况下,我想使用Git使index.php和系统文件夹保持最新.我想要遵守的另一件事是应用程序文件夹的名称.(您可以在index.php中更改应用程序文件夹的路径.)保持名称相同可以直接放入文件夹,然后离开.
我试图通过使用git子模块来实现这一点(见下文),但是子模块不允许您从目标存储库中指定目录.
git submodule add https://github.com/philsturgeon/codeigniter-reactor.git/code-igniter/system system
Run Code Online (Sandbox Code Playgroud)
任何线索我怎么能实现这一目标?
关系:
Item belongs to Product
Product belongs to User
Run Code Online (Sandbox Code Playgroud)
项目范围:
scope :search, ->(search_term) {
select('products.name, users.*, products.brand, COUNT(products.id)')
.joins(:product => :user)
.where('users.name = ? OR products.brand = ?', search_term, search_term)
.group('products.id')
}
Run Code Online (Sandbox Code Playgroud)
以上结果在以下SQL语句中:
SELECT products.name, users.*, products.brand, COUNT(products.id) FROM "items"
INNER JOIN "products" ON "products"."id" = "items"."product_id"
INNER JOIN "users" ON "users"."id" = "products"."user_id"
WHERE (users.name = 'Atsuete Lipstick' OR products.brand = 'Atsuete Lipstick')
GROUP BY products.id
Run Code Online (Sandbox Code Playgroud)
这里的问题是发生错误:
ActiveRecord::StatementInvalid: PG::Error: ERROR: column "users.id"
must appear in the GROUP BY clause …
Run Code Online (Sandbox Code Playgroud) 这是我无法用Cake做的一件事.我已经尝试了几次而无法理解它.我是主持人,如果有人可以指出他们如何设置它(高级安装),它可以帮助.
编辑
我已阅读文档,但我收到错误.我想我一直都读得太好了.
编辑 我刚发现这篇文章. http://www.ad7six.com/MiBlog/ProductionSetup
我的模型中目前有一种方法可以抓取网站并将记录插入数据库。
def self.scrape
#scrape
#insert into database
end
Run Code Online (Sandbox Code Playgroud)
我设置了一个控制器方法来调用它:
def scrape
Website.send_later(:scrape)
end
Run Code Online (Sandbox Code Playgroud)
抓取工作正常,并且已通过控制台运行它进行了测试。但是,通过调用controller方法激活它来运行它是行不通的。
我试过rake jobs:work
说以下内容:
[Worker(host:thorpe-desktop pid:6962)] Starting job worker
[Worker(host:thorpe-desktop pid:6962)] Class#scrape completed after 0.5068
[Worker(host:thorpe-desktop pid:6962)] 1 jobs processed at 0.5898 j/s, 0 failed ...
Run Code Online (Sandbox Code Playgroud)
我在数据库表中看不到应该插入数据的任何内容。
我认为这很简单.
我有一个Codeigniter函数,它从表单中获取输入并将它们插入到数据库中.我想Ajax化这个过程.目前函数的第一行从表单中获取id字段 - 我需要更改它以从Ajax帖子(它引用包含必要值的表单中的隐藏字段)获取id字段.我该怎么办?
我的Codeigniter控制器功能
function add()
{
$product = $this->products_model->get($this->input->post('id'));
$insert = array(
'id' => $this->input->post('id'),
'qty' => 1,
'price' => $product->price,
'size' => $product->size,
'name' => $product->name
);
$this->cart->insert($insert);
redirect('home');
}
Run Code Online (Sandbox Code Playgroud)
和jQuery Ajax函数一样
$("#form").submit(function(){
var dataString = $("input#id")
//alert (dataString);return false;
$.ajax({
type: "POST",
url: "/home/add",
data: dataString,
success: function() {
}
});
return false;
});
Run Code Online (Sandbox Code Playgroud)
一如既往,非常感谢提前.
我目前在我的应用程序中有这个代码:
def comment_poster(comment)
if comment.user
"posted by #{comment.user.username} #{time_ago_in_words(comment.created_at)} ago"
else
"posted by anonymous"
end
end
Run Code Online (Sandbox Code Playgroud)
但是,这只适用于我在几秒钟前和几年前发布的情况:
posted by teejay about 1 year ago
posted by teejay about 1 month ago
Run Code Online (Sandbox Code Playgroud)
当我几天前编辑created_at值时,它给了我:
posted by thorpe {{count}} days ago
Run Code Online (Sandbox Code Playgroud)
我该怎么办才能使它发挥作用而失去它 {{count}}
编辑:如果这意味着什么,我正在使用Rails 2.3.5
编辑:#2
我通过粘贴固定的问题这段代码在config/locales/en.yml
datetime:
distance_in_words:
half_a_minute: "half a minute"
less_than_x_seconds:
one: "less than 1 second"
other: "less than %{count} seconds"
x_seconds:
one: "1 second"
other: "%{count} seconds"
less_than_x_minutes:
one: "less than a minute"
other: "less than …
Run Code Online (Sandbox Code Playgroud) var ready;
ready = function() {
var imageChooser, productChooser;
productChooser = function() {
var self;
self = this;
self.quantityId = ko.observable(1);
self.quantityText = ko.observable('QTY');
self.genderId = ko.observable(1);
self.sizeId = ko.observable(1);
self.colorId = ko.observable(1);
self.fullSize = ko.observable('SIZE');
this.setGenderAndSize = function(stringtoparse, thestring) {
var values;
values = stringtoparse.split(":");
self.fullSize("SIZE: " + thestring);
self.genderId(values[0]);
self.sizeId(values[1]);
};
this.setQuantity = function(quantity) {
self.quantityId(quantity);
self.quantityText("QTY: " + quantity);
};
};
imageChooser = function() {
this.clicked = ko.observable();
this.setBigImage = (function(message) {
alert(message);
}).bind(this);
};
ko.applyBindings(new productChooser(), …
Run Code Online (Sandbox Code Playgroud) php ×3
codeigniter ×2
activerecord ×1
cakephp ×1
delayed-job ×1
escaping ×1
git ×1
jquery ×1
knockout.js ×1
mysql ×1
orm ×1
postgresql ×1