欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

whats new in rails2

程序员文章站 2022-07-14 14:34:27
...

ActiveRecord

  • Post.new.from_xml ({:title => "Hello!", :body => "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 %>
  • 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
     
  • 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