我有一個自定義註冊控制器,但我不想重寫設計的創建操作。當我嘗試註冊用戶時,出現此錯誤:Ruby on Rails:自定義設計註冊控制器,要求創建動作
Unknown action
The action 'create' could not be found for Devise::RegistrationsController
這是因爲我有自定義註冊控制器嗎?如果是這樣,這是否意味着我需要複製所有我沒有從這裏覆蓋的操作:https://github.com/plataformatec/devise/blob/master/app/controllers/devise/registrations_controller.rb
或者因爲我的應用程序有問題嗎?
我的路線:
devise_for :user, :controllers => { :registrations => "devise/registrations" }, :skip => [:sessions] do
get 'signup' => 'devise/registrations#new', :as => :new_user_registration
post 'signup' => 'devise/registrations#create', :as => :user_registration
end
這是我的色器件登記控制器
class Devise::RegistrationsController < DeviseController
skip_before_filter :require_no_authentication
def edit
@user = User.find(current_user.id)
@profile = Profile.new
end
def update
# required for settings form to submit when password is left blank
if params[:user][:password].blank? && params[:user][:password_confirmation].blank?
params[:user].delete(:password)
params[:user].delete(:password_confirmation)
end
@user = User.find(current_user.id)
if @user.update_attributes(params[:user])
set_flash_message :notice, :updated
# Sign in the user bypassing validation in case his password changed
sign_in @user, :bypass => true
redirect_to after_update_path_for(@user)
else
render "edit"
end
end
protected
def after_update_path_for(resource)
user_path(resource)
end
def after_sign_up_path_for(resource)
user_path(resource)
end
end
這是登記表:
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
...
<div>
<%= button_tag :type => :submit, :class => "btn btn-large btn-inverse" do %>
Sign up
<% end %>
</div>
...
<% end %>
這是有效的。爲什麼它不能被設計成文件夾名稱? – hellomello
實際上,我認爲它可以) 但我通常遵循Rails的命名約定我調試此類應用的痛苦經歷:錯誤往往是非常意外的地方,往往是唯一的原因是,一些命名約定不被採納。 –
@RoaringStones你錯過了's'並且註冊結束。該名稱必須是registrations_controller.rb – Ricbermo