`
CaiDeHen
  • 浏览: 90304 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

#94 ActiveResource Basics

阅读更多
ActiveResource allows you to easily communicate between multiple Rails applications. See how in this episode.
# models/product.rb
class Product < ActiveResource::Base
  self.site = "http://localhost:3000"
end

# models/post.rb
class Post < ActiveRecord::Base
  def product
    @product ||= Product.find(product_id) unless product_id.blank?
  end
end

<!-- 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 %>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics