天天看點

railscast cast1-70的說明 也可以說是個人記錄

1 session和變量運用?

2-3 models動态指令

4 轉移到models指令

5 with_scope 運用

6 |p| p.name 可以轉換成&:name

7 layouts 模闆全部介紹(他說的=。=)

8 内容顯示 yield css等

9 保護password不被記錄

10-12 測試說明

13 session安全儲存方式

14 console示範model指令

15 model conditions用法

17 聯合

18 flash 顯示錯誤、提示等

19-21 管理者 驗證之類 以及簡單登陸制作

22-23 聯合INCLUDE減少讀取時間(加資料項等)

24 irb 錯誤堆棧查找

25 SQL注入conditions=> 用['?','%'+params[:xx]+'%']

26 預設送出跨表傳輸   model 隻保護 attr_protected :admin  隻允許attr_accessable :name

27 跨站攻擊 h(XX) 避免

28 數組(1..2).to_a  a.in_groups_of(4)4個一組 用于多列顯示 a.in_groups_of(4,false)消除nil 換0

則用0填

29 依舊分組 按時間段來 @[email protected]_by{|t| t.due_at.beginning_of_month}

   VIEW裡 <% @t_months.each do |month,tasks| %>      或者 .keys.sort.each do |month|

  <h2><%= month.strftime('%B') %></h2>

  <% for task in tasks %>        @t_months[month]

   <%= task.name %>

  <% end %>

30 标題頭。。view helper幾個方式

31 時間格式 to_s(:long) (:short) (:db)  strftime()格式可用ri strftime檢視

   格式類型可以在environment.rb裡面定義

   Time::DATE_FORMATS[:due_time]=strftime("due at %B %d on %I:%M %p")

32 ruby chronic根據字元串轉成資料庫日期

   rescue ArgumentError相當于try  (begin rescue end)

   errors.add(:due_at,"is invalid") if @due_at_invalid 錯誤追加

33 自己做插件

validates_presence_of :name 必填

   插件 stringify_time :due_at

   script/generate plugin stringify_time

  -init.rb

 require "stringify_time"

 class ActiveRecord::Base

   extend StringifyTime

 end

  -stringify_time.rb

 module StringifyTime

  def stringify_time(*names)

   names.each do |name|

     define_method "#{name}_string" do

  read_attribute(name).to_s(:db)

     end

     define_method "#{name}_string=" do |time_str|

       begin

        write_attribute(name,Time.parse(time_str)

              rescue ArgumentError

        instance_variable_set("@#{name}_invalid",true)

       end

     end

#+++ 

     define_method "#{name}_invalid" do

  instance_variable_get("@#{name}_invalid")

     end

   end

  end

 end

#從下面語句改成以上插件

#  def due_at_string

#    due_at.to_s(:db)

#  end

#  def due_at_string=(due_at_str)

###    self.due_at =Time.parse(due_at_str)

#  rescue ArgumentError

#    @due_at_invalid = true

#  end

# end

if due_at_invalid?

34 routes表編寫 xx_path 相對路徑 xx_url 完整路徑 帶參數的路徑設定

35 rest 多餘項目 routes表填加 map.resources :task,:collection => {:completed => :get}

   :member =>{:complete => :put}

   @task.update_attribute :completed_at,Time.now 直接更新完成某一項

36 subversion 版本控制

   rails blob

   cd blob

   mv config/database.yml config/database_example.yml複制?

   rm -r log/*

   rm -r tmp/*

   cd ..

   mv blob trunk

   mkdir tags

   mkdir branches

   svn import. svn://localhost/blob -m "initial import" --username rbates

   cd..

   svn co svn://localhost/blob/trunk blob

   cd blob  

   cp config/database_example.yml config/database.yml

   svn status

   svn propset svn:lgnore database.yml config/

   svn propset svn:lgnore "*" log//

   svn propset svn:lgnore "*" tmp//

   svn propset svn:lgnore "*" tmp/

   svn status

   svn commit -m "lgnoring files"

   script/generate model item -c

   svn status

   svn add db/schema.rb 填加過去了

   textmate 反點項目commit過去。。 還能寫注釋

   那其他的怎麼辦=。= 逼我用netbean?

  -x 直接寫SVN?

37 簡單搜尋

38 預覽

39 自定義錯誤框

40 應該是講admin_area

41 models conditional 各種驗證 attr_accessor :xx 允許xx傳入

42 with_options 選項 像each do |what| 還有根據一個controller 多次指定那樣

   with_options :if =>:should_validate_password do |what|

   what.validates_presence_of :password # == validates_presence_of :password :if

=>:should_validate_password

43 ajax rjs

flash[:notice]

flash.discard 免得rjs傳輸 不清除

44 js ajax debug

45 rjs一些prototype特效

46 route 顯示 說明參數 包括查找相似頭 然後跳轉

47 many to many 通過has_many thought

48 console 指令提示

49 怎樣查API

50 送出RAILS項目?

51 will_paginate(翻頁插件介紹)

52 checkboxes更新項目 沒什麼好說的

53 錯誤跳轉

54 debug rails。。。

55 幹淨的view制作方法

56 LOG顯示

57 選擇或者建立關聯

58 用模闆構件普通頁

59 建立資料庫項  防過期處理

60 不用fixtures的測試

61 發送郵件

62 hacking activerecord 驗證還是測試。。 搞不清楚

63 url美化 def to_param "#{id}-#{permalink}" find(params[:id].to_i)

64 自定義helper

65 stopping spam 不懂

66 自定義rake 任務

67 使用者管理插件

68 使用者郵件認證?

69 markaby in helper? 感覺是個類似haml插件 沒haml好

70 依舊route接收params說明 自定義routes

繼續閱讀