2012-09-20 31 views
0

我在我的rails應用程序中使用strong_parameters和devise_invitable。如果我離開它,因爲它是「禁止屬性」運行時錯誤是我得到的。所以,我做了以下內容:如何解決「邀請令牌不能爲空」的DeviseInvitable

  1. 創建使用rails g controller users/invitations
  2. 新增:invitations => "users/invitations"一個新的控制器,以devise_for
  3. 填充的用戶/ invitations.rb像這樣:

    class Users::InvitationsController < Devise::InvitationsController 
        def update 
        self.resource = resource_class.accept_invitation!(allowed_params) 
    
        if resource.errors.empty? 
         set_flash_message :notice, :updated 
         sign_in(resource_name, resource) 
         respond_with resource, :location => after_accept_path_for(resource) 
        else 
         respond_with_navigational(resource){ render :edit } 
        end 
    end 
    
    private 
    
        def allowed_params 
        params.permit(:utf8,:authenticity_token,:invitation_token, :_method, 
        {user: [:invitation_token,:password,:password_confirmation]}, :commit, 
        :action,:controller) 
        end 
    end 
    

然而,當我這樣做時,我得到錯誤「邀請令牌不能爲空」。我檢查了allowed_pa​​rams的值,使用puts,它似乎在那裏。但是,我仍然得到錯誤。

回答

1

我發現我的問題,並在wiki上回答。

+0

太棒了!這完美的作品!謝謝 ! –