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
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 ><%= h @post . product . name %></ strong >
10 <% end %>
11
12
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 ><%= h @post . product . name %></ strong >
10 <% end %>
11
12