Wicked gem Rails - How to create a new object

♀尐吖头ヾ 提交于 2019-12-06 05:07:48

问题


The Building Partial Objects Step by Step page on the Wicked Gem Wiki explains how to create an object step by step with wicked.

But how do I have to create a new Product object?

Do i have to do that in the new action in the ProductsController ? And where do i have to redirect to ?


回答1:


The following statement is given in the Building Partial Objects Step by Step page.

This also means to get to the create action we don't have a product_id yet so we can either create this object in another controller and redirect to the wizard, or we can use a route with a placeholder product_id such as [POST] /products/building/build in order to hit this create action.

You can create the object in another controller and redirect to wizard or use a route with a placeholder to hit the create action.




回答2:


Here is a sample from my app which worked for me

class RegistrationsController < Devise::RegistrationsController
  protected

  def after_sign_up_path_for(resource)
    user_background = resource.build_user_background
    user_background.save
    user_background_build_path(user_background.id, :first_step_name)
  end

end

This creates the UserBackground object and then passes the user to the first step of the wicked controller with the newly created object id.



来源:https://stackoverflow.com/questions/14662279/wicked-gem-rails-how-to-create-a-new-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!