I've built a wizard in my rails 4 app using Wicked. I've specifically followed this guide, the only difference is I'm doing this with a nested resource. I'm having difficulties with my controller actions that are supposed to find the object the form is building using its ID.
The current flow of the app is a user clicks a button that creates the object and is redirected to the first step of the wizard which updates the object throughout a series of steps. The problem is I'm not passing the object's ID through the parameters because I'm passing the wizard's step in the ID field.
Button that creates object
<%= link_to business_loan_application_path(@user), method: :post, :class => "btn btn-success" do %><% end
%>
LoanApplication Controller
def create
@user = current_user
@loanapplication = @user.loan_applications.new
@loanapplication.save(validate: false)
redirect_to business_loan_application_wizard_path(@user.id,LoanApplication.form_steps.first)
end
I need to somehow pass the :loan_application_id into the business_loan_application_wizard_path arguments.
Error
Couldn't find LoanApplication without an ID
LoanApplication belongs_to Business through has_many relationship.
{"business_id"=>"55", "id"=>"business_details"}
business_details is the first step in the wizard. These are the params that are passed when I first create the object via a button with a put request.
Wizard Controller
class WizardController < ApplicationController
include Wicked::Wizard
before_filter :authenticate_user!
before_filter :require_business
steps *LoanApplication.form_steps
def show
@business = current_user
@loanapplication = LoanApplication.find(params[:loan_application_id])
render_wizard
end
def update
@business = current_user
@loanapplication = @business.loan_applications.last
@loanapplication.update_attributes(loan_application_params(step))
render_wizard @loanapplication
end
end