### Installing Development Gems (Shell) Source: https://github.com/zombocom/wicked/blob/main/README.md This command uses Bundler to install the necessary development gems specified in the project's Gemfile. It's the standard first step when setting up a Ruby project for development or testing. ```Shell $ bundle install ``` -------------------------------- ### Installing the Wicked Gem in Ruby Source: https://github.com/zombocom/wicked/blob/main/README.md This code snippet shows how to add the Wicked gem to your Gemfile, which is the first step in integrating it into a Ruby on Rails project. After adding this line, you need to run `bundle install` to download and install the gem. ```ruby gem 'wicked' ``` -------------------------------- ### Testing Wicked Show Action with RSpec Source: https://github.com/zombocom/wicked/blob/main/README.md Provides an example of testing a specific step within the `show` action of a Wicked wizard controller using RSpec. It shows how to make a GET request with the step ID passed as a parameter. ```RSpec # Test find_friends block of show action get :show, params: { id: :find_friends } ``` -------------------------------- ### Set Wicked Steps Dynamically Source: https://github.com/zombocom/wicked/blob/main/README.md Example Ruby code showing how to set Wicked wizard steps dynamically using `self.steps = [...]` within a `before_action` method. The `setup_wizard` call must follow to initialize Wicked with the new step list. ```ruby include Wicked::Wizard before_action :set_steps before_action :setup_wizard ``` -------------------------------- ### Passing Parameters to finish_wizard_path (Ruby) Source: https://github.com/zombocom/wicked/blob/main/README.md This example demonstrates how to pass parameters to the `finish_wizard_path` method using the `render_wizard` helper in the `show` and `update` actions. The parameters provided to `render_wizard` (e.g., `{ hello: 'world' }`) become accessible within the `finish_wizard_path(params)` method definition. ```Ruby steps :first_step, :second_step def show # ... render_wizard(nil, {}, { hello: 'world' }) end def update # ... render_wizard(@user, {}, { hello: 'world' }) end def finish_wizard_path(params) # here you can access params and that would be equal to { hello: 'world' } end ``` -------------------------------- ### Running Tests Across All Appraisals (Shell) Source: https://github.com/zombocom/wicked/blob/main/README.md This command executes the `rake test` task against all the Gemfiles generated by `appraisal install`. It allows running the test suite against multiple dependency configurations to ensure compatibility. ```Shell $ appraisal rake test ``` -------------------------------- ### Using Wicked Controller Methods in Ruby Source: https://github.com/zombocom/wicked/blob/main/README.md Lists essential controller methods for managing wizard steps, including setting the order, getting current/next/previous steps, skipping or jumping to steps, rendering the current step (with optional save logic), and checking the position of a step relative to the current one. ```Ruby steps :first, :second # Sets the order of steps step # Gets current step next_step # Gets next step previous_step # Gets previous step skip_step # Tells render_wizard to skip to the next logical step jump_to(:specific_step) # Jump to :specific_step render_wizard # Renders the current step render_wizard(@user) # Shows next_step if @user.save, otherwise renders render_wizard(@user, context: :account_setup) # Shows next_step if @user.save(context: :account_setup), otherwise renders wizard_steps # Gets ordered list of steps current_step?(step) # is step the same as the current request's step past_step?(step) # does step come before the current request's step in wizard_steps future_step?(step) # does step come after the current request's step in wizard_steps previous_step?(step) # is step immediately before the current request's step next_step?(step) # is step immediately after the current request's step ``` -------------------------------- ### Define Translated Wicked Steps in YAML Source: https://github.com/zombocom/wicked/blob/main/README.md Example YAML configuration for a Spanish locale file (`es.yml`) defining translations for Wicked wizard step names (`first`, `second`) under the `wicked` key. These translations will be used in the URL. ```yaml es: hello: "hola mundo" wicked: first: "uno" second: "dos" ``` -------------------------------- ### Testing Wicked Update Action with RSpec Source: https://github.com/zombocom/wicked/blob/main/README.md Provides an example of testing a specific step within the `update` action of a Wicked wizard controller using RSpec. It shows how to make a PATCH request with the step ID and user parameters. ```RSpec # Test find_friends block of update action patch :update, params: {'id' => 'find_friends', "user" => { "id" => @user.id.to_s }} ``` -------------------------------- ### Overriding finish_wizard_path in Ruby Source: https://github.com/zombocom/wicked/blob/main/README.md Explains how to customize the final destination URL after completing a wizard by overriding the `finish_wizard_path` method in the wizard controller. The example shows redirecting to the user's profile page. ```Ruby def finish_wizard_path user_path(current_user) end ``` -------------------------------- ### Set Default I18n Locale in Rails Config Source: https://github.com/zombocom/wicked/blob/main/README.md Example Ruby code in `config/application.rb` to set the default locale for the Rails application's I18n system. This determines the locale used if no specific locale is provided in the URL or other means. ```ruby config.i18n.default_locale = :de ``` -------------------------------- ### Set I18n Locale in Rails Controller Source: https://github.com/zombocom/wicked/blob/main/README.md Example Ruby code for setting the `I18n.locale` based on a URL parameter (`params[:locale]`) in a Rails application controller using a `before_action` filter. This ensures the correct locale is active for each request. ```ruby before_action :set_locale private def set_locale I18n.locale = params[:locale] if params[:locale].present? end def default_url_options(options = {}) {locale: I18n.locale} end ``` -------------------------------- ### Define Custom Wicked Step URLs in YAML Source: https://github.com/zombocom/wicked/blob/main/README.md Example YAML configuration for an English locale file (`en.yml`) defining custom URL names for Wicked wizard steps (`first`, `second`) under the `wicked` key. This allows changing URLs without altering controller logic or view file names. ```yaml en: hello: "hello world" wicked: first: "verify_email" second: "if_you_are_popular_add_friends" ``` -------------------------------- ### Wicked Controller Logic Without wizard_value Source: https://github.com/zombocom/wicked/blob/main/README.md Example Ruby controller code using a `case` statement on the raw `step` value. When using translated steps, `step` will contain the translated value, which will not match the original step names defined in the controller, causing this logic to fail. ```ruby steps :confirm_password, :confirm_profile, :find_friends def show case step when :find_friends @friends = current_user.find_friends end render_wizard end ``` -------------------------------- ### Setting Up Appraisal Gemfiles (Shell) Source: https://github.com/zombocom/wicked/blob/main/README.md This command uses the `appraisal` gem to generate Gemfiles for different dependency combinations defined in the Appraisals file. This is typically used in Ruby projects to test compatibility with various versions of dependencies like Rails. ```Shell $ appraisal install ``` -------------------------------- ### Using Wicked View/URL Helpers in Ruby Source: https://github.com/zombocom/wicked/blob/main/README.md Provides a quick reference for view and URL helper methods available within a Wicked wizard, including relative and fully qualified paths for current, specific, next, and previous steps. These helpers are only active inside a wizard context. ```Ruby wizard_path wizard_path(:specific_step) next_wizard_path previous_wizard_path wizard_url wizard_url(:specific_step) next_wizard_url previous_wizard_url # These only work while in a Wizard # You can have multiple wizards in a project with multiple `wizard_path` calls ``` -------------------------------- ### Adding Routes for Wicked Wizard Controller Source: https://github.com/zombocom/wicked/blob/main/README.md Adds a standard Rails resource route for the `after_signup` controller in the `config/routes.rb` file. This creates the necessary URL helpers and routes for the wizard steps. ```Ruby resources :after_signup ``` -------------------------------- ### Implementing Wicked Wizard Show Action with Case Statement Source: https://github.com/zombocom/wicked/blob/main/README.md Defines the `show` action for the wizard controller. It retrieves the current user, uses a case statement to execute step-specific logic, and calls `render_wizard` at the end to render the view corresponding to the current step. ```Ruby class AfterSignupController < ApplicationController include Wicked::Wizard steps :confirm_password, :confirm_profile, :find_friends def show @user = current_user case step when :find_friends @friends = @user.find_friends end render_wizard end end ``` -------------------------------- ### Generating Rails Controller for Wicked Wizard Source: https://github.com/zombocom/wicked/blob/main/README.md Uses the Rails generator command to create a new controller named `AfterSignupController`. This controller will serve as the core component for managing the steps of the after-signup wizard. ```Shell rails g controller after_signup ``` -------------------------------- ### Generating Wizard Paths with Parameters (Ruby) Source: https://github.com/zombocom/wicked/blob/main/README.md This snippet shows how to use the `next_wizard_path` and `wizard_path` helper methods to generate URLs for wizard steps while including additional parameters. These parameters can then be accessed in the controller's `show` or `update` actions when navigating to the generated path. ```Ruby next_wizard_path({ hello: 'world' }) wizard_path(nil, { hello: 'world' }) # the wizard_path with the step specified would look like this wizard_path(:wicked_finish, wizard_id: @user.id, hello: 'world') ``` -------------------------------- ### Contributing via Git Workflow Source: https://github.com/zombocom/wicked/blob/main/CONTRIBUTING.md Follow these steps to fork the repository, create a feature branch, commit your changes, push the branch, and open a pull request to contribute code to the project. ```Shell git checkout -b my-new-feature ``` ```Shell git commit -am 'Add some feature' ``` ```Shell git push origin my-new-feature ``` -------------------------------- ### Including Wicked::Wizard Module in Controller Source: https://github.com/zombocom/wicked/blob/main/README.md Includes the `Wicked::Wizard` module in the `AfterSignupController` to enable wizard functionality. The `steps` method is then used to define the sequence and names of the steps in the wizard. ```Ruby class AfterSignupController < ApplicationController include Wicked::Wizard steps :confirm_password, :confirm_profile, :find_friends # ... ``` -------------------------------- ### Inheriting from Wicked::WizardController (Alternative) Source: https://github.com/zombocom/wicked/blob/main/README.md Presents an alternative method for enabling Wicked wizard functionality by inheriting the controller directly from `Wicked::WizardController`. The steps are defined using the same `steps` method. ```Ruby class AfterSignupController < Wicked::WizardController steps :confirm_password, :confirm_profile, :find_friends # ... ``` -------------------------------- ### Include Translated Wicked Wizard Module Source: https://github.com/zombocom/wicked/blob/main/README.md Replace the standard module inclusion with `Wicked::Wizard::Translated` to enable Internationalization (I18n) and custom URL support for your wizard step names. ```ruby include Wicked::Wizard::Translated ``` -------------------------------- ### Setting Wizard Steps Based on Flow (Ruby) Source: https://github.com/zombocom/wicked/blob/main/README.md This private method `set_steps` dynamically sets the sequence of steps for a wizard based on the `flow` parameter received. It assigns an array of symbols representing step names to `self.steps`. This method should be called before `setup_wizard` in a controller using the Wicked gem. ```Ruby private def set_steps if params[:flow] == "twitter" self.steps = [:ask_twitter, :ask_email] elsif params[:flow] == "facebook" self.steps = [:ask_facebook, :ask_email] end end ``` -------------------------------- ### Linking to Next Wicked Wizard Step in View Source: https://github.com/zombocom/wicked/blob/main/README.md Uses the `next_wizard_path` helper within an ERB view template to generate a link that automatically directs the user to the subsequent step in the defined wizard sequence. ```ERB <%= link_to 'skip', next_wizard_path %> ``` -------------------------------- ### Skipping Wicked Step with Parameters in Ruby Source: https://github.com/zombocom/wicked/blob/main/README.md Demonstrates how to use the `skip_step` method to redirect to the next logical step while passing parameters. Unlike `redirect_to`, `return` should not be called immediately after `skip_step` as the redirect happens within `render_wizard`. ```Ruby skip_step(foo: "bar") ``` -------------------------------- ### Jumping to Wicked Step with Parameters in Ruby Source: https://github.com/zombocom/wicked/blob/main/README.md Shows how to use the `jump_to` method to redirect directly to a specific step while passing parameters. Similar to `skip_step`, `return` should not be called immediately after `jump_to`. ```Ruby jump_to(:specific_step, foo: "bar") ``` -------------------------------- ### Linking to Specific Wicked Wizard Step in View Source: https://github.com/zombocom/wicked/blob/main/README.md Uses the `wizard_path` helper in an ERB view, passing a specific step name as an argument, to create a link that navigates directly to that named step within the wizard. ```ERB <%= link_to 'skip', wizard_path(:find_friends) %> ``` -------------------------------- ### Include Base Wicked Wizard Module Source: https://github.com/zombocom/wicked/blob/main/README.md This is the standard way to include the Wicked Wizard module in a Rails controller to enable basic wizard functionality. ```ruby include Wicked::Wizard ``` -------------------------------- ### Running Tests Against Specific Appraisal (Shell) Source: https://github.com/zombocom/wicked/blob/main/README.md This command executes the `rake test` task against a specific Gemfile configuration defined in the Appraisals file, identified here by the version '4.1'. This is useful for testing against a particular dependency version or debugging issues specific to one configuration. ```Shell $ appraisal 4.1 rake test ``` -------------------------------- ### Conditionally Skipping Wicked Wizard Step Source: https://github.com/zombocom/wicked/blob/main/README.md Demonstrates how to use the `skip_step` method within the `show` action's case statement. Based on a condition (e.g., user having a Facebook access token), the current step can be skipped, and the wizard will proceed to the next step automatically. ```Ruby def show @user = current_user case step when :find_friends if @user.has_facebook_access_token? @friends = @user.find_friends else skip_step end end render_wizard end ``` -------------------------------- ### Accessing Wicked Wizard Step Constants (Ruby) Source: https://github.com/zombocom/wicked/blob/main/README.md This snippet lists the constants provided by the Wicked gem for referencing special wizard steps: `Wicked::FIRST_STEP`, `Wicked::LAST_STEP`, and `Wicked::FINISH_STEP`. These constants represent the first step, the last defined step, and the final redirect action after the last step, respectively, and can be used to generate paths or redirects. ```Ruby Wicked::FIRST_STEP Wicked::LAST_STEP Wicked::FINISH_STEP ``` -------------------------------- ### Implementing Wicked Wizard Update Action with Object Handling Source: https://github.com/zombocom/wicked/blob/main/README.md Defines the `update` action to process form submissions for the current step. It updates the user object, handles Devise sign-in if necessary, and calls `render_wizard @user` to automatically save the object and proceed to the next step on success or re-render on failure. ```Ruby class AfterSignupController < ApplicationController include Wicked::Wizard steps :confirm_password, :confirm_profile, :find_friends def update @user = current_user case step when :confirm_password @user.update(user_params) end sign_in(@user, bypass: true) # needed for devise render_wizard @user end private def user_params params.require(:user) .permit(:email, :current_password) # ... end end ``` -------------------------------- ### Creating Form for Wicked Wizard Update Action Source: https://github.com/zombocom/wicked/blob/main/README.md Creates an HTML form in an ERB view using `form_for`. It explicitly sets the `url` to `wizard_path` and the `method` to `:put` to ensure the form submission is routed correctly to the `update` action of the wizard controller. ```ERB <%= form_for @user, url: wizard_path, method: :put do |f| %> <%= f.password_field :password %> <%= f.password_field :password_confirmation %> <%= f.submit "Change Password" %> <% end %> ``` -------------------------------- ### Wicked Controller Logic With wizard_value Source: https://github.com/zombocom/wicked/blob/main/README.md Corrected Ruby controller code using `wizard_value(step)` in a `case` statement. `wizard_value` returns the original, untranslated step name, allowing comparison with the canonical values defined in the controller or used for view file names. ```ruby steps :confirm_password, :confirm_profile, :find_friends def show case wizard_value(step) when :find_friends @friends = current_user.find_friends end render_wizard end ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.