Ruby on Rails/Rails3関連 http://www.ark-web.jp/sandbox/wiki/5237.html
なんか見つけたらわかることだけでもいいからメモっていくことに。
まとめサイト †
Rails 3 and the Real Secret to High Productivity より。 †
- いきなり分からんが ^^;
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 †
- 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 †
- scaffoldのテンプレートのカスタマイズが楽になるらしい
- RAILS_ROOT/lib/templates/rails/scaffold_controller/controller.rb に
置いておけばそれをテンプレートにしてくれるらしい。 - scaffoldに限らずgeneratorは全部?
Rails 3 の Gem 管理ツール Bundler を使う - ursmの日記 †
- rake gem ではなく、Bundlerという仕組みを使うらしい
- config/environment.rbではなく、Gemfileに読み込みたいgemを書くらしい
- gem bundle でインストールされるらしい
![[PukiWiki] [PukiWiki]](image/sandbox.gif)



