---
title: "whats new in rails2"
author: "swachian"
date: "2008-05-25T23:34:39Z"
tags: []
slug: "whats-new-in-rails2"
draft: false
lastmod: "2008-05-25T23:34:39Z"
id: 196813
url: "https://swachian.iteye.com/blog/196813"
---

# ActiveRecord

- Post.new**.from\_xml** ({:title =&gt; "Hello!", :body =&gt; "text"}.to\_xml)
- CSRF
- Partial layouts
  
  ```
  <% render :partial => "post", :layout => "window" %>
  or with a block:
  <% render :layout => "window", :locals => { :name => "Recent" } do %>
    <% for post in @recent_posts %>
      <h2><%=h post.title %></h2>
      <!‐‐ ... ‐‐>
    <% end %>
  <% end %>
  ```

<!--THE END-->

- HTTP authentication
- simply\_helpful
  
  ```
  dom_class(@person) => "person"
  dom_class(Person) => "person"
  dom_class(@person, :edit) => "edit_person"
  dom_id(@person) => "person_1234"
  dom_id(Person.new) => "new_person"
  ```
- url\_for
  
  ```
  url_for(@post) works like 
  post_path(@post).
  
  url_for(Post.new) works like 
  new_post_path.
  
  Works with link_to, redirect_to, etc.
  
  render :partial => @post works like 
  render :partial => "post", :object => @post
  
  render :partial => @posts works like 
  render :partial => "post", :collection => @posts
  ```

<!--THE END-->

- form\_for
  
  ```
  <% form_for @person do |f| %>
    <%= f.text_field :name %>
  <% end %>
  
  Determines form action based on the 
  record. (e.g. post_path or new_post_path)
  ```
- Hash#except is the inverse of Hash#slice
- Rake tasks
  
  ```
  rake db:create and db:create:all
  rake db:drop and db:drop:all
  rake db:reset
  rake db:rollback (defaults to STEP=1)
  rake db:version
  
  rake routes
  ```
- Initializer hooks
  
  ```
  Rails load order:
  1. config/preinitializer.rb
  2. config/environment.rb
  3. config/environments/RAILS_ENV.rb
  4. config/initializers/*.rb
  ```

 

 

 

http://delynnberry.com/projects/userstamp/

http://svn.techno-weenie.net/projects/plugins/

http://dev.rubyonrails.org/browser/plugins