- 浏览: 94262 次
- 性别:
- 来自: 成都
最新评论
-
xylffxyfpp:
应该改成慎用each
万恶的"delete",慎用数组的delete -
xylffxyfpp:
a = [1,2,3,4,5,6]
a.each do ...
万恶的"delete",慎用数组的delete -
CaiDeHen:
受教了,我也不知道当时为什么会在这个地方这样子用。其他地方也是 ...
万恶的"delete",慎用数组的delete -
wosmvp:
感觉太乱了为什么不在User模型中来个 named_scope ...
万恶的"delete",慎用数组的delete -
jiachengxi38:
不知道楼主这样的逻辑想法从何而来,权限访问的思想好像在lZ这里 ...
万恶的"delete",慎用数组的delete
文章列表
Learn how to use with_scope - a very powerful method which will allow your custom find methods to accept any find options. Just like magic!
# models/task.rb
def self.find_incomplete(options = {})
with_scope :find => options do
find_all_by_complete(false, :order => 'created_at DESC')
...
- 2008-12-02 21:28
- 浏览 774
- 评论(0)
Move a find into the model to clean up the controllers and remove duplication. Also see how you can call these custom find methods through an association.
# tasks_controller.rb
def index
@tasks = Task.find_incomplete
end
# models/task.rb
def self.find_incomplete
find_all_by_complete(fa ...
- 2008-12-02 21:27
- 浏览 640
- 评论(0)
No need to pass foreign keys in find conditions, just do the find through a has_many association.
# projects_controller.rb
def show
@project = Project.find(params[:id])
@tasks = @project.tasks.find_all_by_complete(false)
end
- 2008-12-02 21:26
- 浏览 622
- 评论(0)
Shorten simple finds considerably and improve readability by using the dynamic find_all_by and find_by methods.
# tasks_controller.rb
def incomplete
@tasks = Task.find_all_by_complete(false)
end
def last_incomplete
@task = Task.find_by_complete(false, :order => 'created_at DESC')
end ...
- 2008-12-02 21:24
- 浏览 599
- 评论(0)
Learn a quick way to improve performance. Just store the end result of an expensive command in an instance variable!
# application.rb
def current_user
@current_user ||= User.find(session[:user_id])
end
- 2008-12-02 21:23
- 浏览 614
- 评论(0)
今天和朋友又聊到了盈利模式,感到很奇怪。现在一谈到什么,就是盈利模式啊,核心竞争力啊,满天飞。于是乎,出去走走,透透气,寻找答案。
路过菜市场,看到一家买猪肉的,仔细一看,居然整个菜市场只有他一家,队排了很长。纳闷了。为啥这种必需品,入门低的居然还可以这种垄断。。于是我决定最后调查。等了很久,大概要1个小时吧。人终于没有了。老板也磨着刀开始休息了。我上前去问老板:
“老板,能聊聊吗?”
“好啊”老板可能感到很奇怪,居然有人和他聊天。“聊啥”
我接着说:“就问下问题吧,呵呵。你。。”我本来想翻译一下的,还是算了。“你的盈利模式是啥”
“啥子叫盈利模式 ...
一个人对自己的自我认识,自我肯定来自于5个方面:最亲的亲人,最好的朋友,爱人,自我,其他。
最亲的亲人:一般是自己的父母中的一个,也可能是自己亲戚中对自己影响最大的人。他们的重要性在于在亲情方面 ...
首先解释下,什么叫初创,初创不是指你有了社会背景,有了人脉、有了资金之后的创业。而是指你踏入社会不仅或刚踏入的时候的创业,这个时候,缺少人脉,缺少资金。
朋友,我觉得分四种:酒肉朋友,生活中的朋友 ...
Chapter 3: Systems Design: Job-Order Costing
Absorption costing: A costing method that includes all manufacturing costs --- direct materials, direct labor, and both variable and fixed manufacturing overhead – in the cost of a product.
Allocation base: A measure of activity such as direct labor-hour ...
- 2008-06-12 14:19
- 浏览 1664
- 评论(0)
Chapter 2: Cost Terms, Concepts, and Classifications
Administrative costs: All executive, organizational, and clerical costs associated with the general management of an organization rather than manufacturing or selling.
Common cost: A cost that is incurred to support a number of cost objects but t ...
- 2008-06-11 10:34
- 浏览 1267
- 评论(0)
Chapter 2: Market Forces: Demand and Supply
Ad valoren tax: a percentage tax; the sales tax is a well-known example.
Change in demand: Changes in variables other than the price of a good, such as income or the price of another good, lead to a change in demand. This corresponds to a shift of the ent ...
- 2008-06-10 14:41
- 浏览 1509
- 评论(0)
Chapter 1: The Fundamentals of Managerial Economics
Accounting cost: the costs most often associated with the costs of producing. Costs that appear on the income statements of firms.
Accounting profits: the total amount of money taken in from sales (total revenue, or price times quantity sold) minu ...
- 2008-06-06 11:11
- 浏览 1119
- 评论(0)
Chapter 1 Managerial Accounting and the Business Environment
Budget: A detailed plan for the future, usually expressed in formal quantitative terms.
Business process: A series of steps that are followed to carry out some task in a business.
Chief Financial Officer (CFO) The member of the top manag ...
- 2008-06-05 13:04
- 浏览 2059
- 评论(0)
先说验证问题。
按照传统的file_column :image, :magick => xxx
无论你想不想验证,file_column 都会验证上传的文件是不是图形文件,如果不是,它会在你的模型错误里面加"invalid image"。该错误验证的地方在 magick_file_column.rb里。查找
if options[:magick][:image_required]
@magick_errors ||= []
@magick_errors << "invalid image"
end
可以将第3行修改为 ...
User has_many Categories
Category has_many Posts
当Category和Post同为多态时。这样
class User < ActiveRecord::Base
has_many :categories, :as => :owner #owner_id owner_type
has_many :posts, :through => :categories
end
class Category < ActiveRecord::Base
has_many :posts, :as => :postab ...