なんか見つけたらわかることだけでもいいからメモっていくことに。
** まとめサイト [#ie289c00]
- http://railsnotes.com/rails-3/
** [[Rails 3 and the Real Secret to High Productivity:http://www.scribd.com/doc/15010095/Rails-3-and-the-Real-Secret-to-High-Productivity]] より。 [#q93c7ac3]
- いきなり分からんが ^^;
In Rails 3, ActionController::Base is built on top of ActionController::Metal ...
うーん、
-- ActionController::Metalというのが用意される
-- それには、callbacks, rendering, layouts, helpersがないがその分高速
-- ActionController::BaseはActionController::Metalを継承している?
-- ActionController::Baseが、必要に応じて内部的にincludeしてくれるんで、callbacksなどを使わなければActionController::Baseがめちゃ早いってこと? わからん。。
- URL /loginを GETメソッドなら、SessionsController#loginに
- POSTメソッドなら、SessionsController#createに
- そんな感じでルーティングする、ってことかな。URLにこだわりたい人向け?
contrller :sessions do
match 'login', do
get :new, :as => :login
post :create
end
end
- routesで、resourcesの入れ子のとき、こんな風に記述できるらしい。
resources :projects, :controller => :project do
resources :attachments
resources :participants do
:put => :update_all, :on => :collection
end
resources :companies do
resources :people
resource :avator
end
end
- XSS対策、デフォルトでサニタイズされるらしい。rawでサニタイズさせないらしい。
<%# => "I'm hacked you good! <sciprt>" %>
<%= comment.body %>
<%# => "I'm hacked you bad! <script>" %>
<%= raw comment.body %>
- link_to_remote -> link_to :remote => true みたいになって、生成されるHTMLにJavaScriptが含まれなくなり、unobtrusive javascript になるらしい
<%= link_to "Delete", @comment, :remote => true, :method => :delete %>
<a href="/comments/1" data-remote="true" data-method="delete">Destroy</a>
- このdata-xxx っていうのは、HTML5のdata-xxx アトリビュートらしい(参考: http://zaa.ch/past/2009/5/23/unobtrusive_javascript_in_rails_3/)
** [[My Five Favorite Things About Rails 3 | Engine Yard Blog:http://www.engineyard.com/blog/2009/my-five-favorite-things-about-rails-3/]] [#q3a9d594]
- respond_toが宣言的に記述できるらしい
respond_to :html, :xml # class level
def create
@user = User.new(params[:user])
flash[:notice] = 'User was successfully created.' if @user.save
respond_with(@user)
end
- ActiveModelというのができて、ActiveRecordを継承しなくてもバリデーションできるらしい。
class Person
include ActiveModel::Validations
validates_presence_of :name
attr_accessor :name
def initialize(name)
@name = name
end
end
Person.new.valid? #=> false
Person.new.errors #=> {:name => ["cannot be blank"]} # localizable of course
Person.new("matz").valid? #=> true
** [[Customizing your scaffold template become easier in Rails3:http://zigzag.github.com/2010/01/18/customizing-your-scaffold-template-become-easier-in-rails3.html]] [#wbfaa4fe]
- scaffoldのテンプレートのカスタマイズが楽になるらしい
- RAILS_ROOT/lib/templates/rails/scaffold_controller/controller.rb に
置いておけばそれをテンプレートにしてくれるらしい。
- scaffoldに限らずgeneratorは全部?
** [[Rails 3 の Gem 管理ツール Bundler を使う - ursmの日記:http://d.hatena.ne.jp/ursm/20100111/1263219023]] [#uf8b1b4c]
- rake gem ではなく、Bundlerという仕組みを使うらしい
- config/environment.rbではなく、Gemfileに読み込みたいgemを書くらしい
- gem bundle でインストールされるらしい
-
vendor/gem
#blikifooter(志田)