Flowdock

Good notes posted by RobinWu

RSS feed
November 7, 2008
3 thanks

Add spacer template

<%= render :partial => “product”, :collection => @products, :spacer_template => “product_ruler” %>

September 25, 2008 - (v2.1.0)
3 thanks

Compare old and new form for

Old form for

<% form_for :user, :url => users_path do %>
  <%= render :partial => 'form' %>
  <%= submit_tag 'Create' %>
<% end %>

New form for

<% form_for(@user) do |f| %>
  <%= render :partial => f %>
  <%= submit_tag 'Create' %>
<% end %>
September 25, 2008
22 thanks

All methods

create_table :table do |t|

  t.column # adds an ordinary column. Ex: t.column(:name, :string)
  t.index # adds a new index.
  t.timestamps
  t.change # changes the column definition. Ex: t.change(:name, :string, :limit => 80)
  t.change_default # changes the column default value.
  t.rename # changes the name of the column.
  t.references
  t.belongs_to
  t.string
  t.text
  t.integer
  t.float
  t.decimal
  t.datetime
  t.timestamp
  t.time
  t.date
  t.binary
  t.boolean
  t.remove
  t.remove_references
  t.remove_belongs_to
  t.remove_index
  t.remove_timestamps
end
September 25, 2008
18 thanks

All methods

change_table :table do |t|

  t.column # adds an ordinary column. Ex: t.column(:name, :string)
  t.index # adds a new index.
  t.timestamps
  t.change # changes the column definition. Ex: t.change(:name, :string, :limit => 80)
  t.change_default # changes the column default value.
  t.rename # changes the name of the column.
  t.references
  t.belongs_to
  t.string
  t.text
  t.integer
  t.float
  t.decimal
  t.datetime
  t.timestamp
  t.time
  t.date
  t.binary
  t.boolean
  t.remove
  t.remove_references
  t.remove_belongs_to
  t.remove_index
  t.remove_timestamps
end
September 25, 2008
6 thanks

Expressions in the sum method

Person.sum(“2 * age”)

Person.sum(:age, :conditions=>'1 = 2')
August 23, 2008
3 thanks

Include two level has many model example

class Issue < ActiveRecord::Base

  has_many :journals
end

class Journal < ActiveRecord::Base
  belongs_to :issue
  has_many :details, :class_name => "JournalDetail", :dependent => :delete_all
end

class JournalDetail < ActiveRecord::Base
  belongs_to :journal
end

<hr/>

issue = Issue.find(:first, :include => {:journals => :details}

log record follow:

SELECT * FROM `issues` LIMIT 1
SELECT `journals`.* FROM `journals` WHERE (`journals`.`journalized_id` IN (1) and `journals`.`journalized_type` = 'Issue' AND (dustbin <> 1))
SELECT `journal_details`.* FROM `journal_details` WHERE (`journal_details`.journal_id IN (1,2,876177898,935815637))

when execute follow code, then not build sql sentent:

issue.journals
issue.journals[0].details
July 4, 2008
6 thanks

Window open a dialog of no menu, no status, have scroll

Example

link_to name, url, :popup => ['dialog name','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes']
July 4, 2008
12 thanks

Add empty option and text is -select-

select :object, :method, options, :prompt => ‘-select-’