1

我是 RoR 的新手......只是警告你:)

我在 routes.rb 中制作了这条路线:

  scope :module => :mobile, :as => :mobile do
    constraints(:subdomain => /m/) do
      resources :home
         devise_for :users, :path => "", :path_names => { :sign_in => "login", :sign_out => "logout", :sign_up => "signup" }, :controllers => {:sessions => "sidebar/sessions"}

      resources :disclosures # Will have new, get, look up a disclosure

      devise_for :users, :path => "", :path_names =>
          { :sign_in => "login", :sign_out => "logout", :sign_up => "signup" }
          # How do I tell is to also take care of the confirm account screen?
    end
  end

我制作了这个 HAML 页面:

-content_for :primary_content do
  .content_container
    %strong{:class => "code", :id => "message"} Hello Alex!

  -content_for :primary_content do
    -if signed_in?
      =render "sidebar/common/primary_navigation"
    -else
      =render "devise/sessions/form"

当用户未登录时,它给了我这个错误:

undefined local variable or method `resource' for #<#<Class:0x147fe1990>:0x147fdab40>

1: = form_for(resource, :as => resource_name, :url => session_path(resource_name), :html => {:id => "login-form"}) do |f| 
2:   %fieldset.field-container
3:     = f.label(t :label_login) 
4:     .input

这个堆栈跟踪:

app/views/devise/sessions/_form.html.haml:1:in `_app_views_devise_sessions__form_html_haml__2025707780_2630401320'
app/views/mobile/home/index.html.haml:26:in `_app_views_mobile_home_index_html_haml__2141491110_2759485880'
app/views/mobile/home/index.html.haml:22:in `_app_views_mobile_home_index_html_haml__2141491110_2759485880'
app/views/mobile/home/index.html.haml:1:in `_app_views_mobile_home_index_html_haml__2141491110_2759485880'
app/controllers/mobile/home_controller.rb:6:in `index'

因此,如果我理解正确,它不知道如何处理代码的表单部分。那是对的吗?我做错了什么导致这个问题?我如何解决它?

谢谢!!

4

1 回答 1

3

您不需要呈现设计表单。

所以删除这个:

-else
      =render "devise/sessions/form"

您需要将此添加到要验证的控制器的顶部:

before_filter :authenticate_user!, :only => [:edit, :update, :destroy]

如果用户未通过身份验证,这将导致设计重定向到登录表单。如果他已经通过身份验证,则将呈现您的正常视图。

于 2012-04-17T17:25:00.593 回答