Ruby on rails 在Rails中的操作之间插入控制器操作-最佳实践
在Rails的流程中添加更多步骤时,最佳实践(或常规实践)是什么 例如,我正在使用,我想添加一个多步骤表单,人们在尝试“添加到购物车”产品时应该填写该表单 将产品添加到购物车的当前spree实现基本上是:Ruby on rails 在Rails中的操作之间插入控制器操作-最佳实践,ruby-on-rails,redirect,controllers,spree,Ruby On Rails,Redirect,Controllers,Spree,在Rails的流程中添加更多步骤时,最佳实践(或常规实践)是什么 例如,我正在使用,我想添加一个多步骤表单,人们在尝试“添加到购物车”产品时应该填写该表单 将产品添加到购物车的当前spree实现基本上是: ProductsController\show->OrdersController\edit 这会将产品添加到购物车,并将您留在购物车上 所以我想知道,为了在spree中对核心代码进行最小程度的更改,我该如何使其变得更像这样: ProductsController#show->SurveysC
ProductsController\show->OrdersController\edit
这会将产品添加到购物车,并将您留在购物车上
所以我想知道,为了在spree中对核心代码进行最小程度的更改,我该如何使其变得更像这样:
ProductsController#show->SurveysController#show->(调查资料…)->OrdersController#edit
我想做的是:
- 修改“products/show.html.erb”,使其转到products\u controller.rb。还修改products_controller.rb以放置
,我可以在SurveysController中处理该路径会话[:重定向到]=order\u checkout\u路径
- 或者只是弹出那些额外的东西,当我看到最后一个时,让它调用原始方法
Lance在RESTful web应用程序中,这不是一个非常标准的流程,因此无论您做什么,都必须是一些黑客,因为Rails没有提供简单的方法 会话变量对我来说似乎很好。简明扼要。不过,您可能希望使密钥更具描述性,这样您就不会看到将来的冲突。您可以查看: 这个插件提供面试风格 控制器中的工作流,类似于 TurboTax,但不需要储蓄 立即将模型添加到数据库中。 所有数据都存储在会话中 除非被推翻
你试过orders\u controller\u decorator.rb吗
OrdersController.class_eval do
before_filter :show_survey, :only => :populate
def new_survey
#regular stuff
respond_to do |format|
format.html do
#if you've already been through this process, skip the before_filter
redirect_to(new_order_line_item_url(session[:order_line_item])) and return if session[:order_line_item]
#otherwise point to the form and store the order data in session
session[yeahyougetthepoint]
render 'new_survey'
end
end
end
def create_survey
#regular stuff
respond_to do |format|
format.html {redirect_to new_order_line_item(session[:order_line_item]}
end
end
我不是百分之百确定“添加到购物车”的过程,但通过在日志中挖掘整个过程可以很容易地推断出来。把你自己的流量投入到狂欢中有点奇怪,但这绝对是可以做到的