我正在尝试使用 <%= render "/shopping/coupons/cou" %> 创建部分模板。不太确定哪里出错了。谢谢!
这是错误信息。
undefined method `model_name' for NilClass:Class
Extracted source (around line #3):
1: <h4> Coupon </h4>
2:
3: <%= form_for(@coupon, :url => shopping_coupon_path(@coupon)) do |f| %>
4: <div class="field">
5: <%= f.label :code %>
6: <%= f.text_field :code %>
这是我的优惠券控制器
class Shopping::CouponsController < Shopping::BaseController
def cou
form_info
end
def create
@coupon = Coupon.find_by_code(params[:coupon][:code])
if @coupon && @coupon.eligible?(session_order) && update_order_coupon_id(@coupon.id)
flash[:notice] = "Successfully added coupon code #{@coupon.code}."
redirect_to shopping_orders_url
else
form_info
flash[:notice] = "Sorry coupon code: #{params[:coupon][:code]} is not valid."
render :action => 'show'
end
end
private
def form_info
@coupon = Coupon.new
end
def update_order_coupon_id(id)
session_order.update_attributes( :coupon_id => id )
end
end