在到处搜索有关如何解决此问题后,我决定发布一个问题。我正在尝试将自定义操作“create_pro”添加到设计注册控制器,以便我可以创建一个具有附加字段的用户(专业用户)。此表单与用户的设计创建操作位于同一页面上。
提交表单后,我不断收到以下错误:
未知动作
找不到 Devise::RegistrationsController 的操作“create_pro”
我怎样才能解决这个问题?
路线
devise_for :users,:controllers => { :registrations => "registrations" }
devise_scope :user do
post "gopro", :to => "devise/registrations#create_pro"
end
注册控制器
class RegistrationsController < Devise::RegistrationsController
before_filter :authenticate_user!, :only => :token
def new
super
end
def create
@user = User.new(params[:user])
if @user.save
sign_in @user
flash[:notice] = "Welcome to Banking Analytics."
redirect_to '/mybank'
else
render :action => :new
end
end
def create_pro
@user = User.new(params[:user])
if @user.save
sign_in @user
flash[:notice] = "Welcome to Banking Analytics."
redirect_to '/mybank'
else
render :action => :new
end
end
end
看法
<div class="signup_form_basic">
<%= simple_form_for @user, :url => url_for(:controller => 'registrations', :action => 'create_pro') do |f| %>
<%= f.error_notification %>
<%= f.input :email, :required => true, :autofocus => true, :label => 'Username ( Your Email )', :placeholder => 'Email Address' %>
<%= f.input :password, :required => true, :autofocus => true, :label => 'Password', :placeholder => 'Password' %>
<%= f.input :password_confirmation, :required => true, :autofocus => true, :label => 'Confirm Password', :placeholder => 'Password Confirmation' %>
<%= f.button :submit, "Sign Up >>", class: 'btn btn-inverse' %>
<% end %>
</div>