Ruby on Rails - 当我非常确定我有模板时,错过了模板错误

时间:2012-04-18 13:57:54

标签: ruby-on-rails ruby devise

我有这条路线:

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

      resources :home

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

和这个控制器:

class Mobile::SessionsController < ApplicationController
  def create
  end
end

并在此目录下:/app/views/mobile/sessions/new.html.haml

这是new.html.haml文件中的代码:

= content_for :page_title do
  = t :page_title_login
= content_for :primary_content do
  #login_box
    .span6
      #traditional-login
    .span4
= content_for :before_closing_body_tag do
  configure_login_form(#{request.xhr?.to_s.downcase});

但是在我登录后,我在浏览器中收到此错误:

Missing template mobile/sessions/create, application/create with {:locale=>[:en, :en], :formats=>[:html], :handlers=>[:haml, :erb, :builder]}. Searched in: * "/Users/alexgenadinik/projects/cmply/cmply-app/app/views" * "/Library/Ruby/Gems/1.8/gems/ckeditor-3.6.3/app/views" * "/Library/Ruby/Gems/1.8/gems/kaminari-0.13.0/app/views" * "/Library/Ruby/Gems/1.8/gems/devise-2.0.4/app/views"

这告诉我系统认为我没有new.html.haml文件。但我显然有那个档案。所以我不确定是什么问题。并且想到我做错了什么?

提前致谢!!

1 个答案:

答案 0 :(得分:3)

这里的错误并不是你错过了new.html.haml文件;您缺少create.html.haml或远离create动作的重定向。通常在登录后重定向,因此请尝试将控制器操作更改为以下内容:

class Mobile::SessionsController < ApplicationController
  def create
    redirect_to root_url
  end
end

或者无论你想让访客结束的地方。