Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 948
Blue Bird Avatar asked Feb 02 '13 13:02

Blue Bird


2 Answers

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.

like image 187
Sasi Avatar answered Nov 04 '22 22:11

Sasi


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.

like image 42
Abram Avatar answered Nov 04 '22 21:11

Abram