0

userログイン、許可、:emailおよび完了には:passwordWicked gem を使用しています。ユーザー モデルとプロファイル モデル。for Profile は、views/devise/registrations/new.html.erb の非表示フィールドとして設定されます。問題について説明し、関連するコードをリストします。profilefirst_namelast_nameusernamebiohas_one :profileaccepts_nested_attributes_for :profilebelongs_to :useruser_id

Devise と Wicked のドキュメントを何度も読みましたが、この問題がわかりません。Wicked のコントローラーは after_signup_controller です。binding.pryafter_signup#showに挿入したところ、サインアップ プロセスを実行してもそのコントローラー/アクションにヒットしないことがわかりました。サインアップした後、Wicked ウィザードはスキップされたようです。「/after_signup/name」(名前は Wicked での最初のステップ) を localhost URL に追加し、after_signup#show で binding.pry を使用すると、Wicked がすべてのステップを実行したことがわかりました。これにより、何かがウィザードへのルートを上書きしていると思われます。

このようにDeviseとWickedを使ってみた人はいますか? sign_up 後に Wicked のルートが上書きされる理由がわかったら、お知らせください。


Rails.application.routes.draw do
  resources :profiles
  resources :posts

  devise_for :users, controller: {
    confirmations:  'users/confirmations',
    # omniauth_callbacks: 'users/omniauth_callbacks'
    passwords:      'users/passwords',
    registrations:  'users/registrations',
    sessions:       'users/sessions',
    unlocks:        'users/unlocks'
  }

  #Wicked Wizard
  resources :after_signup

  root 'posts#welcome_page'

end
class Users::RegistrationsController < Devise::RegistrationsController
  def new
    super
  end

  def create
    super
  end

  protected

  def after_sign_up_path_for(resource)
    '/after_signup'
  end
end

class AfterSignupController < ApplicationController
  include Wicked::Wizard

  steps :name, :username, :bio, :image

    def show
      binding.pry
      @profile = current_user.profile
      render_wizard(@profile)
    end

    def update
      @profile = current_user.profile
      @profile.update(profile_params)
      render_wizard(@profile)
    end

    private

    def profile_params
      params.require(:profile).permit(:username, :first_name, :last_name, :bio, :image, :user_id)
    end
end

class ApplicationController < ActionController::Base
  before_filter :configure_permitted_parameters, if: :devise_controller?

  private

  def configure_permitted_parameters
    devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:email, :password, :password_confirmation, profile_attributes: [:user_id, :first_name, :last_name, :username, :bio, :image])}
    devise_parameter_sanitizer.for(:account_update) { |u| u.permit(:email, :password, :password_confirmation, profile_attributes: [:user_id, :first_name, :last_name, :username, :bio, :image])}
    devise_parameter_sanitizer.for(:sign_in) { |u| u.permit(:login, :username, :email, :password, :remember_me) }
  end
end


##name.html.erb
<%= bootstrap_form_for(@profile, url: wizard_path, method: :put) do |f| %>
<div class="row">
  <div class="field col-xs-8 col-sm-6">
    <div class="field">
      <%= f.text_area :first_name, autofocus: true %>
      <%= f.text_area :last_name, autofocus: true %>
    </div>
  </div>
</div>
<% end %>

<div class="actions">
  <%= f.submit "Next", :class => 'btn btn-primary' %>
  or <%= link_to "skip", next_wizard_path %>
</div>


##username.html.erb
<%= bootstrap_form_for(@profile, url: wizard_path, method: :put) do |f| %>
<div class="row">
  <div class="field col-xs-8 col-sm-6">
    <div class="field">
      <%= f.text_area :username, :placeholder => 'username' autofocus: true %>
    </div>
  </div>
</div>
<% end %>

<div class="actions">
  <%= f.submit "Next", :class => 'btn btn-primary' %>
  or <%= link_to "skip", next_wizard_path %>
</div>


##bio.html.erb
<%= bootstrap_form_for(@profile, url: wizard_path, method: :put) do |f| %>
<div class="row">
  <div class="field col-xs-8 col-sm-6">
    <div class="field">
      <%= f.text_area :bio, autofocus: true %>
    </div>
  </div>
</div>
<% end %>

<div class="actions">
  <%= f.submit "Next", :class => 'btn btn-primary' %>
  or <%= link_to "skip", next_wizard_path %>
</div>


##image.html.erb
<%= bootstrap_form_for(@profile, url: wizard_path, method: :put) do |f| %>
<div class="row">
  <div class="field col-xs-8 col-sm-6">
    <div class="field">
      <%= f.text_field :image, autofocus: true %>
    </div>
  </div>
</div>
<% end %>

<div class="actions">
  <%= f.submit "Submit", :class => 'btn btn-primary' %>
</div>

Stack Overflow に質問を投稿するのはこれが初めてです。この問題に対処することに加えて、リストしたファイルが多すぎる場合はお知らせください。

4

0 に答える 0