Wicked gem Rails - How to create a new object
The Create Partial Step by Step Objects page on the Wicked Gem Wiki explains how to create an object step by step using wicked
.
But how do I create a new object Product
?
Should I do this in a new activity in ProductsController
? And where should I redirect?
source to share
The next instruction is on the Constructing Partial Step by Step Objects 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 an object in another controller and redirect to master, or use a placeholder route to click on the create action.
source to share
Here is an example from my application that 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
Creates an object UserBackground
and then passes the user to the first step of the evil controller with the newly created object id.
source to share