简体   繁体   中英

Wicked gem Rails - How to create a new object

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 ?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM