2013-02-27 22 views
0

我有一個使用Devise(和Omniauth)進行驗證的Ruby on Rails應用程序。使用Rails/Devise的其他一組驗證視圖

我想與我的應用程序中嵌入頁面的iOS應用程序(無法控制)進行集成。這個應用程序需要我的頁面具有特定的視覺外觀,所以我想創建一組額外的身份驗證視圖。

在設計文檔周圍挖掘後,我收集了,也許我需要routes.rb創建一個新的devise_scope塊:

devise_scope :user do 
    get "iosapp/users/sign_in" => "devise/sessions#iosapp_new" 
    post "iosapp/users/sign_in" => "devise/sessions#iosapp_create" 
    delete "iosapp/users/sign_out" => "devise/sessions#iosapp_destroy" 
end 

我開了一組新的對應於那些路線的觀點:

app/views/devise/sessions/iosapp_new.html.rb 
app/views/devise/sessions/iosapp_create.html.rb 
app/views/devise/sessions/iosapp_destroy.html.rb 

但裝載/iosapp /用戶/ sign_in在瀏覽器導致的Rails錯誤:

undefined method `errors' for nil:NilClass 

該錯誤從devise_helper.rb的第9行(https://github.com/plataformatec/devise/blob/master/app/helpers/devise_helper.rb)莖:

module DeviseHelper 
    # A simple way to show error messages for the current devise resource. If you need 
    # to customize this method, you can either overwrite it in your application helpers or 
    # copy the views to your application. 
    # 
    # This method is intended to stay simple and it is unlikely that we are going to change 
    # it to add more behavior or options. 
    def devise_error_messages! 
    return "" if resource.errors.empty? 

    messages = resource.errors.full_messages.map { |msg| content_tag(:li, msg) }.join 
    ... 

我明明在這裏做得不對,但想不通爲什麼resource是不確定的,從被稱爲當我的「備用「觀點。看起來好像我可能還需要創建額外的控制器方法,但我在文檔中找不到關於此的任何內容。

我是否偏離軌道?還是有更好的方法來實現我的目標?

+0

@Charles,謝謝你,做到了! Boneheaded錯誤在我的一部分。如果您將您的評論添加爲答案,我會接受它爲「官方」的答案。 – Zac 2013-02-28 15:53:59

回答

1

你的新意見需要form_for resource - 你有這個嗎?如果沒有資源,它就無法找到資源上的錯誤,因此錯誤爲零。