1. 首先我们修改order表给他添加个字段shipped_at:
create table orders (
id not null auto_increment,
name varchar(100) not null,
email varchar(255) not null,
address text not null,
pay_type char(10) not null,
shipped_at datetime null,
primary key (id)
);
2. 添加个Action在admin_controller.rb文件中添加个思路方法:
def ship
@pending_orders = Order.pending_shipping
end
3. 给ordermodel实现pending_shipping思路方法:
def self.pending_shipping
find(:all, :conditions => "shipped_at is null")
end
4. 还是老道路M有了C有了还差个V现在来补上:
在Viewsadmin目录下创建个ship.rhtml文件内容如下:
<h1>Orders To Be Shipped</h1>
<%= form_tag(:action => "ship") %>
<table cellpadding="5" cellspacing="0">
<%= render(:partial => "order_line", :collection => @pending_orders) %>
</table>
<br />
<input type="submit" value=" SHIP CHECKED ITEMS " />
<%= end_form_tag %>
<br>
注意兰色行参数partial指明了个局部模板collection参数指定了使用数据集合这里是pending_orders思路方法取出order如果不明白(其实我自己也不明白J)先不着急等下看看效果图就好了
5. 下面我们还要再进行步实现上面order_line这个页面还是在Viewsadmin目录下创建个_order_line.rhtml文件作为约定文件名使用“_”作为前缀文件内容如下:
<tr valign="top">
<td ="olnamebox">
<div ="olname"><%= h(order_line.name) %></div>
<div ="oladdress"><%= h(order_line.address) %></div>
</td>
<td ="olitembox">
<% order_line.line_items.each do |li| %>
<div ="olitem">
<span ="olitemqty"><%= li.quantity %></span>
<span ="olitemtitle"><%= li.product.title %></span>
</div>
<% end %>
</td>
<td>
<%= check_box("to_be_shipped", order_line.id, {}, "yes", "no") %>
</td>
</tr>
6. 看看效果图:
OK这次就到这里目前为止我也仅仅还是从书本上拷贝代码有很多细节还不清楚后面争取有自己理解写出来
最新评论