CaiDeHen 发表于 2013-2-7 20:37:49

#94 ActiveResource Basics

ActiveResource allows you to easily communicate between multiple Rails applications. See how in this episode.
# models/product.rbclass Product < ActiveResource::Baseself.site = "http://localhost:3000"end# models/post.rbclass Post < ActiveRecord::Basedef product    @product ||= Product.find(product_id) unless product_id.blank?endend<!-- views/posts/edit.html.erb --><p><%= f.label :product_id %><%= f.collection_select :product_id, Product.find(:all), :id, :name %></p><!-- views/posts/show.html.erb --><% if @post.product %><strong><%=h @post.product.name %></strong><% end %>
页: [1]
查看完整版本: #94 ActiveResource Basics