0
A
回答
1
儘管Devise允許controller configuration,但通過模態登錄的表示方式在視圖內處理得更爲恰當。
默認情況下,Devise的視圖打包在gem中。要訪問視圖模板,你可以運行下面的命令:
rails generate devise:views
運行上面的發電機將複製所有的設計的視圖模板在app/views/devise
目錄,允許您根據需要修改標記。
有關配置視圖的更多詳細信息可在Devise's documentation中找到。
希望它有幫助!
0
你只需要重寫設計的控制器,例如:
控制器(控制器/ registrations_controller.rb)
class RegistrationsController < Devise::RegistrationsController
# POST /resource
def create
build_resource(sign_up_params)
resource.save
yield resource if block_given?
if resource.persisted?
if resource.active_for_authentication?
set_flash_message :notice, :signed_up if is_flashing_format?
sign_up(resource_name, resource)
respond_with resource, location: after_sign_up_path_for(resource)
else
set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_flashing_format?
expire_data_after_sign_in!
respond_with resource, location: after_inactive_sign_up_path_for(resource)
end
else
clean_up_passwords resource
set_minimum_password_length
respond_with resource
end
end
protected
# Signs in a user on sign up. You can overwrite this method in your own
# RegistrationsController.
def sign_up(resource_name, resource)
sign_in(resource_name, resource)
end
# The path used after sign up. You need to overwrite this method
# in your own RegistrationsController.
def after_sign_up_path_for(resource)
after_sign_in_path_for(resource)
end
# The path used after sign up for inactive accounts. You need to overwrite
# this method in your own RegistrationsController.
def after_inactive_sign_up_path_for(resource)
scope = Devise::Mapping.find_scope!(resource)
router_name = Devise.mappings[scope].router_name
context = router_name ? send(router_name) : self
context.respond_to?(:root_path) ? context.root_path : "/"
end
# The default url to be used after updating a resource. You need to overwrite
# this method in your own RegistrationsController.
def after_update_path_for(resource)
signed_in_root_path(resource)
end
# Authenticates the current scope and gets the current resource from the session.
def authenticate_scope!
send(:"authenticate_#{resource_name}!", force: true)
self.resource = send(:"current_#{resource_name}")
end
def sign_up_params
params.require(:user).permit(:name, :email, :password, :password_confirmation)
end
def account_update_params
devise_parameter_sanitizer.sanitize(:account_update)
end
def translation_scope
'devise.registrations'
end
end
助手(助手/ registrations_helper.rb)
module RegistrationsHelper
def resource_name
:user
end
def resource
@resource ||= User.new
end
def devise_mapping
@devise_mapping ||= Devise.mappings[:user]
end
end
路線(routes.rb中)
devise_for :users, :controllers => { :registrations => 'registrations' }
模態(視圖/用戶/ _new_user.html.erb)
<div class="modal fade" id="form-validation-modal" tabindex="-1" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<%= form_for(resource,
:as => resource_name,
:url => user_registration_path(resource),
:html => {:id => "sign_up_user"}) do |f| %>
<%= devise_error_messages! %>
<div class="modal-header">
<h4 class="modal-title" id="myModalLabel">
Create a new user
</h4>
</div>
<div class="modal-body">
<div class="form-group">
<%= render 'shared/error_messages' %>
<%= f.label :name, "Name:"%>
<%= f.text_field :name, class: "form-control" %>
</div>
<div class="form-group">
<%= f.label :email, "Email:"%>
<%= f.email_field :email, class: "form-control" %>
</div>
</div>
<div class="modal-footer">
<button id="dismiss" type="button" class="btn btn-default" data-dismiss="modal" style="float:left">Cancel</button>
<%= f.submit "Save user", class: "btn btn-success btn-medium", style: "float:right" %>
</div>
<% end %>
</div>
</div>
</div>
相關問題
- 1. ruby-on-rails devise gem
- 2. Rails控制器RESTful設計
- 3. 覆蓋設計控制器
- 4. 添加用戶配置文件的設計註冊控制器
- 5. 如何使用devise parent_controller設計繼承控制器,但跳過ActiveAdmin設計控制器?
- 6. 如何配置設計gem發送電子郵件到資源?
- 7. Rails,Devise&Omniauth - 設置問題
- 8. 如何繼承設計控制器
- 9. Ruby on Rails:如何配置Devise Mailer?
- 10. 用devise rails設置recaptcha 3.1
- 11. 在Gem更新(Rails 3,Devise + Omniauth)上設計路由錯誤
- 12. Rails + Devise - 會話控制器解釋
- 13. 如何覆蓋設計控制器?
- 14. rails rspec與devise gem共享示例
- 15. 更改設計控制器的佈局
- 16. 如何爲rails-settings gem創建設置配置頁面?
- 17. 如何在rails中設置angularjs ng控制器form_for view
- 18. 如何處理Rails配置Gem
- 19. 設計:同時覆蓋設計路線和控制器
- 20. 使用devise gem進行rails 4認證
- 21. 如何將Twitter配置移出控制器? (Rails)
- 22. 設計的更新控制器
- 23. 設計一個報告控制器Rails
- 24. Rails設計會話控制器
- 25. Ruby on Rails的gem「Devise」在應用程序/控制器中甚至沒有控制器文件?
- 26. Rails/Devise:如何爲/ users/edit修改控制器?
- 27. 如何在Rails 3中自定義Devise控制器?
- 28. 如何在Rails 3中更改Devise的根控制器路徑?
- 29. Devise Gem - 如何清除緩存中的配置值
- 30. 如何設置Mailboxer(Gem)Views for Rails 4