· 2 min read
Screencast: Mehrseitige Formulare mit Wicked
Downloads in verschiedenen Formaten:
Resourcen:
terminal
[bash] rails g controller user_steps [/bash]
user_steps_controller.rb
[ruby] class UserStepsController < ApplicationController include Wicked::Wizard steps :personal, :social def show @user = current_user render_wizard end def update @user = current_user @user.attributes = params[:user] render_wizard @user end private
def redirect_to_finish_wizard redirect_to root_url, notice: “Thank you for signing up.” end end [/ruby]
user_steps/personal.html.erb
[html]
Tell us a little about yourself.
<%= render layout: ‘form’ do |f| %>
<%= f.text_field :name %>
<%= f.date_select :date_of_birth, start_year: 1900, end_year: Date.today.year, include_blank: true %>
<%= f.text_area :bio, rows: 5 %>
user_steps/social.html.erb
[html]
Where can we find you?
<%= render layout: ‘form’ do |f| %>
<%= f.text_field :twitter_username %>
<%= f.text_field :github_username %>
<%= f.text_field :website %>
user_steps/_form.html.erb
[html] <%= form_for @user, url: wizard_path do |f| %> <% if @user.errors.any? %>
<% end %> <%= yield f %>users/new.html.erb
[html]
Sign Up
<%= form_for @user do |f| %> <% if @user.errors.any? %>
<% end %><%= f.text\_field :email %>
<%= f.password\_field :password %>
<%= f.password\_field :password\_confirmation %>
users_controller.rb
[ruby] def create @user = User.new(params[:user]) if @user.save session[:user_id] = @user.id redirect_to user_steps_path else render :new end end [/ruby]
models/user.rb
[ruby] validates_format_of :twitter_username, without: /W/, allow_blank: true # validates_presence_of :twitter_username, if: :on_social_step? [/ruby]