我知道这可能是一个重复的问题,但它确实让我发疯,有人可以帮助我......
在bills_controller中,我有一个帖子操作:apply_repay_list
,在此操作中我生成一个表单:@jd_form
,其中包含有关该帐单的详细信息,并且可以自动提交,我想发布它到payment
行动
逻辑是:
用户在myBills.html.erb
,他可以看到他应该支付多少钱,
在页面底部,当他点击时,有一个付款单按钮
按钮,他需要payment.html.erb
,然后他可以选择paypal或支付宝等付款方式来支付账单。
问题是:我可以生成表单,但我对如何表示困惑
将其发布到付款操作,当我点击付款单按钮时,我得到了
nill class for html.safe
,这意味着@jd_form
永远不会传递给视图
我在做什么?有人可以帮忙吗?
# bills_controller
def apply_repay_list #post action
..........
......
trading = Trading.new
trading.user_id=@user.id
trading.trading_type=5
trading.money= total_remain_amount
trading.relate_ids = bill_ids[1,bill_ids.length-1]
trading.trading_status=2
trading.cporderid="order#{@user.id}_#{@user.mobile_number}_#{Time.now.to_i}"
trading.save
byebug
trading = Trading.find(trading.id)
@jd_form = Jd.gen_form(trading)
respond_to do |format|
format.html { redirect_to :action => 'payment' , result: @jd_form}
format.json { render json: {status:0,status_text:'ok',data:trading.simple_hash}}
end
end
def payment #get action
end
end
#view
#myBills.html.erb
<%= link_to "pay bill", payment_bills_path, class:"pos_fixed btn-css text_center color_gold font-18"%>
#payment.html.erb
#this is a hidden button, cause the form will be auto submit, and then redirect to
#payment provider like paypal's page
<div style="display:none;">
<%= @jd_form.html_safe %>
</div>
的routes.rb
resources :bills do
collection do
get 'list'
post 'apply_repay'
post 'apply_repay_ahead'
post 'apply_repay_list'
get 'detail'
get 'myBills'
get 'myBillsDetail'
get 'payment'
end
end
答案 0 :(得分:0)
添加新的邮寄路线以处理付款:
resources :bills do
collection do
get 'list'
post 'apply_repay'
post 'apply_repay_ahead'
post 'apply_repay_list'
get 'detail'
get 'myBills'
get 'myBillsDetail'
get 'payment'
post 'perform_payment' # <----
end
end
将新操作添加到控制器:
def perform_payment
# ....
end
将该路线添加到您的form_for:
<%= form_for @jd_form, url: perform_payment_bills_path %>
如果@jd_form有一个你需要在perform_payment操作中使用的id,那么你需要在路由中添加:id:
resources :bills do
collection do
get 'list'
post 'apply_repay'
post 'apply_repay_ahead'
post 'apply_repay_list'
get 'detail'
get 'myBills'
get 'myBillsDetail'
get 'payment'
end
member do
post 'perform_payment' # <----
end
end
形式:
<%= form_for @jd_form, url: perform_payment_bills_path(@jd_form) %>
如果您正在寻找,请告诉我。