如何添加在控制器中使用devise_invitable的功能。我想添加其他字段,如消息,proeject_id以及邀請,但不知道從哪裏開始?任何人都有devise_invitable的經驗?
這裏的devise_invitable:link text
如何添加在控制器中使用devise_invitable的功能。我想添加其他字段,如消息,proeject_id以及邀請,但不知道從哪裏開始?任何人都有devise_invitable的經驗?
這裏的devise_invitable:link text
的devise_inevitable引擎定義了兩個視圖文件和一個控制器。您很可能不需要對其定義的控制器進行任何修改。發送邀請給用戶的形式被定義here,你會覆蓋視圖的渲染,像這樣:
#app/views/invitations/new.html.erb
<% form_for resource_name, resource, :url=> invitation_path(resource_name) do |f| %>
<!-- Totally sweet new user invitation code goes here -->
<% end %>
包含代碼供用戶點擊電子郵件中的鏈接後完成註冊的形式here和你會重寫它的渲染,像這樣:
#app/views/invitations/edit.html.erb
<% form_for resource_name, resource, :url=> invitation_path(resource_name), :html=>{:method => :put } do |f| %>
<!-- Totally sweet new user registration information goes here. -->
<% end %>
第一種觀點是什麼將實際創建的資源對象,所以這是更可能的,你會想是樹立了一個消息用戶看到,他們也被邀請參加什麼項目。您可能還想覆蓋app/views/devise_mailer/invitation.html.erb以更改用戶收到的電子郵件。
爲了覆蓋invitations controller你需要這樣做:
#app/controllers/devise/invitations_controller.rb
class Devise::InvitationsController < ApplicationController
def create
#totally rad create stuff here.
end
end
設計及其擴展都是Rails的引擎,因此請求將首先尋找一個合適的控制器/模型/視圖/幫手將文件存儲在您的應用程序目錄中,然後存儲在供應商/ gems中,然後最終在定義引擎的gem目錄中。
謝謝帕特里克這是非常有用的,但我卡住的地方,我可以覆蓋Invitable控制器嗎?我想要做這樣的事情:def create self.resource = resource_class.invite!(params [resource_name]) if resource.errors.empty? #set_flash_message:notice,:send_instructions render:js =>「alert('Hello Rails');」 結束 – AnApprentice 2010-11-08 22:53:32
我想要做的是創建一個模式對話框,允許用戶邀請其他用戶並添加一條消息。我想讓DEF CREATE控制器用JS迴應,所以我可以更新對話框,但是我無法正常工作。想法? – AnApprentice 2010-11-08 22:54:45
我在上面的答案中引入了關於覆蓋控制器的信息。請記住,這可能會損害您未來升級這款寶石的能力。確保記錄你所做的事情。 – 2010-11-08 23:36:25