Reputation: 1717
I just watched the Railscast on the Wicked gem used to create multi step wizards.
I was wondering if this gem could be used to create a wizard where data is passed forward somehow in the render_wizard
call? Based on my initial tinkering, I do not believe that this is possible. The problem I hope to solve is to create a wizard where the first step takes a country and the second step allows the selection of people from that country.
Is there any easier way to solve this problem? Thanks for the help!
Upvotes: 0
Views: 1925
Reputation: 23
ya you can pass data to the next step through the render method
render_wizard(@user, {}, { hello: 'world', your_param_key: "param value" })
here the params are
params[:hello] == "world"
params[:your_param_key] == "param value"
hope that helps anyone else in the future :)
Upvotes: 0
Reputation: 1368
You could employ a table-less ruby object. Serialize it to the session before each show step and load it up from the session (merging in any new params) before each update step.
before_filter :initialize_wizard, on: [:show, :update]
...
def initialize_wizard
@wizard = YourWizardTempModel.new
@wizard.update_attributes(session['wizard']) if session['wizard'].present?
@wizard.update_attributes(params['wizard']) if params['wizard'].present?
session['wizard'] = @wizard.as_json
end
Then you could have a conditional before_filter that assembled the people selection based on the country_id like such:
before_filter :populate_people, if: "step == 'select_people'"
...
def populate_people
People.find_by_country_id(@wizard.country_id)
end
Upvotes: 2