我有以下模型:
class Coupon < ActiveRecord::Base
belongs_to :company
validates :description, presence: true, length: { maximum: 50 }, uniqueness: { case_sensitive: false }
validates :fine_print, presence: true
end
以及优惠券控制器中的以下方法:
def redeem
if params[:pin] == @coupon.company.pin
redirect_to root_path
else
flash.now[:notice] = "Incorrect Pin"
render :show
end
end
此表单在 a 视图中:
<%= form_for( @coupon, :url => coupons_redeem_path( @coupon ), :html => { :method => :post } ) do |f| %>
<%= label_tag("pin", "Search for:") %>
<%= text_field_tag("pin") %>
<%= f.submit "Close Message" %>
<% end %>
我希望表单在点击提交时调用优惠券控制器中的兑换方法,但出现此错误:
没有路线匹配 [POST] "/coupons/redeem.1"
编辑
这些是我的路线:
resources :companies do
resources :coupons
end
get 'coupons/redeem'