我与Device一起工作,只是将“邪恶”的宝石添加到了我的Rails应用程序中。在我的RegistrationsController中,我定义了以下内容:
class Users::RegistrationsController < Devise::RegistrationsController
def new
super
end
def create
super
end
def update
super
end
protected
def after_sign_up_path_for(resource)
user_steps_path
end
def after_update_path_for(resource)
new_user_profile_path(current_user.id)
end
end
基本上,我希望我的表格在注册后再走一步,那就是地址:
class UserStepsController < ApplicationController
include Wicked::Wizard
steps :address
def show
@user = current_user
render_wizard
end
end
在用户提供了地址后,我希望将他/她重定向到他们的个人资料,他们还可以在其中提供有关自己的信息。我的想法是,这是我的RegistrationsController中的更新操作。还是在完成多步骤表单后,如何重定向到配置文件,这意味着步骤地址已完成?这是address.html.erb:
<%= form_for @user, url: wizard_path do |f| %>
<div class="field">
<%= f.label :street %>
<%= f.text_area :street %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
目前,ActionContoller抱怨我的标头路由并查找ID地址,但我不明白为什么...这是我的ProfilesContorller:
class ProfilesController < ApplicationController
before_action :set_profile, only: [:show, :edit, :update, :destroy]
def show
@user = User.eager_load(:profile).find(params[:user_id])
@profile = @user.profile
@review = Review.new
@reviews = Review.where(profile: @profile)
end
def new
@user = current_user
@profile = Profile.new
end
def edit
@profile = @user.profile
end
def create
@user = current_user
@profile = @user.build_profile(profile_params)
respond_to do |format|
if @profile.save
format.html { redirect_to user_profile_path(current_user.id), notice: 'Profile was successfully created.' }
format.json { render :show, status: :created, location: @profile }
else
format.html { render :new, notice: 'Did not save' }
format.json { render json: @profile.errors, status: :unprocessable_entity }
end
end
end
def update
respond_to do |format|
if @profile.update(profile_params)
format.html { redirect_to user_profile_path(current_user.id), notice: 'Profile was successfully updated.' }
format.json { render :show, status: :ok, location: @profile }
else
format.html { render :edit }
format.json { render json: @profile.errors, status: :unprocessable_entity }
end
end
end
def destroy
@profile.destroy
respond_to do |format|
format.html { redirect_to users_url, notice: 'Profile was successfully destroyed.' }
format.json { head :no_content }
end
end
private
def set_profile
@profile = current_user.profile
end
def profile_params
params.permit(:about, :avatar)
end
end
这是我header.html.erb中的错误部分
<% if current_user.profile == nil %>
<li><span class="bg-primary text-white rounded"><%= link_to 'Create profile', new_user_profile_path%></span></li>
<% else %>
<li><span class="bg-primary text-white rounded"><%= link_to 'My profile', user_profile_path(@user) %></span></li>
<% end %>
<li><span class="bg-primary text-white rounded"><%= link_to 'Log out', destroy_user_session_path, method: :delete %></span></li>
ActionController基本上抱怨第二行和“ new_user_profile_path”。地址如何进入配置文件控制器->新-> ID,以及如何处理标题中提到的错误。谢谢!
答案 0 :(得分:2)
根据您的错误,您的路线中缺少user_id
尝试,new_user_profile_path(@user)
在第二行
所以最后应该是<%= link_to 'Create profile', new_user_profile_path(@user)%>