schneems/wicked — pull request #127 by etipton (2014-06-23 06:03:15+00:00)
Title: Add primary_resource option

I am using a Wicked Wizard nested under a resource type, like so:

```ruby
resources :posts
resources :wizard, controller: 'post_wizard'
```

I want step 1 to do the actual post record creation, and every subsequent step to create auxiliary records or update the post in another manner. I therefore would prefer wicked to set :post_id automagically for me after creating the record in step 1.

This is different from the technique suggested here: https://github.com/schneems/wicked/wiki/Building-Partial-Objects-Step-by-Step which requires you to persist a “blank” record before entering step 1 of the wizard.

With this “primary_resource” technique, you can simply do:

```ruby
class PostWizardController < Wicked::WizardController
primary_resource :post
…
end
```

and then as long as the ```@post``` ivar exists, once it is persisted (its id is set), the render_wizard method will change the params[:post_id] value according. The resulting URLs would look something like:

- Step 1: /posts/new/wizard/step1
- “new” is a placeholder post_id
- If form submission is successful, will update post_id in the url
- Let’s say the id is 12345...
- Step 2: /posts/12345/wizard/step2
- Step X: /posts/12345/wizard/StepX

Thoughts on this technique?

I tried to add an appropriate test and good comments, let me know if I missed anything or if this change is a Bad Idea. :)