诗歌rails之ActiveResource Basics

 1 # models/product.rb
 2 class Product < ActiveResource::Base
 3   self.site = "http://localhost:3000"
 4 end
 5 
 6 # models/post.rb
 7 class Post < ActiveRecord::Base
 8   def product
 9     @product ||= Product.find(product_id) unless product_id.blank?
10   end
11 end
12 
13 
 1 <!-- views/posts/edit.html.erb -->
 2 <p>
 3   <%= f.label :product_id %>
 4   <%= f.collection_select :product_id, Product.find(:all), :id, :name %>
 5 </p>
 6 
 7 <!-- views/posts/show.html.erb -->
 8 <% if @post.product %>
 9   <strong><%=@post.product.name %></strong>
10 <% end %>
11 
12 


posted @ 2010-01-20 09:50  麦飞  阅读(186)  评论(0编辑  收藏  举报