【问题标题】:Missing template sessions/new, application/new with {:locale=>[:en]缺少带有 {:locale=>[:en] 的模板会话/新建、应用程序/新建
【发布时间】:2014-02-14 22:35:33
【问题描述】:

我似乎没有通过 6 次规格测试。好消息是,出于同样的原因,我让他们都失败了!所以,这些是我得到的测试结果:

1) 认证登录页面 失败/错误:在 { 访问 signin_path } 之前 ActionView::MissingTemplate: 缺少模板会话/新,应用程序/新的 {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :咖啡]}。搜索: * "/Users/Brawain/rails_projects/sample_app/app/views" # ./spec/requests/authentication_pages_spec.rb:8:in `block (3 levels) in '

2) 认证登录页面 失败/错误:在 { 访问 signin_path } 之前 ActionView::MissingTemplate: 缺少模板会话/新,应用程序/新的 {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :咖啡]}。搜索: * "/Users/Brawain/rails_projects/sample_app/app/views" # ./spec/requests/authentication_pages_spec.rb:8:in `block (3 levels) in '

3) 具有有效信息的认证登录页面 失败/错误:在 { 访问 signin_path } 之前 ActionView::MissingTemplate: 缺少模板会话/新,应用程序/新的 {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :咖啡]}。搜索: * "/Users/Brawain/rails_projects/sample_app/app/views" # ./spec/requests/authentication_pages_spec.rb:8:in `block (3 levels) in '

4) 具有有效信息的身份验证登录页面 失败/错误:在 { 访问 signin_path } 之前 ActionView::MissingTemplate: 缺少模板会话/新,应用程序/新的 {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :咖啡]}。搜索: * "/Users/Brawain/rails_projects/sample_app/app/views" # ./spec/requests/authentication_pages_spec.rb:8:in `block (3 levels) in '

5) 具有有效信息的身份验证登录页面 失败/错误:在 { 访问 signin_path } 之前 ActionView::MissingTemplate: 缺少模板会话/新,应用程序/新的 {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :咖啡]}。搜索: * "/Users/Brawain/rails_projects/sample_app/app/views" # ./spec/requests/authentication_pages_spec.rb:8:in `block (3 levels) in '

6) 具有有效信息的身份验证登录页面 失败/错误:在 { 访问 signin_path } 之前 ActionView::MissingTemplate: 缺少模板会话/新,应用程序/新的 {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :咖啡]}。搜索: * "/Users/Brawain/rails_projects/sample_app/app/views" # ./spec/requests/authentication_pages_spec.rb:8:in `block (3 levels) in '

这里是相关文件。所以,我的规格:

require 'spec_helper'

describe "Authentication" do

subject { page }

describe "signin page" do
before { visit signin_path }

it { should have_content('Sign in') }
it { should have_title('Sign in') }

describe "with valid information" do
  let(:user) { FactoryGirl.create(:user) }
  before do
    fill_in "Email",    with: user.email.upcase
    fill_in "Password", with: user.password
    click_button "Sign in"
  end

  it { should have_title(user.first) }
  it { should have_link('Profile',     href: user_path(user)) }
  it { should have_link('Sign out',    href: signout_path) }
  it { should_not have_link('Sign in', href: signin_path) }
end
end
end

这是我的实用程序.rb

include ApplicationHelper

def full_title(page_title)
base_title = "Techmasters"
if page_title.empty?
base_title
else
"#{base_title} | #{page_title}"
end
end

def valid_signin(user)
fill_in "Email",    with: user.email
fill_in "Password", with: user.password
click_button "Sign in"
end

RSpec::Matchers.define :have_error_message do |message|
match do |page|
expect(page).to have_selector('div.alert.alert-error', text: message)
end
end

登录页面在 app/views/sessions/new.html.erb

<% provide(:title, "Sign in") %>
<h1>Sign in</h1>

<div class="row">
<div class="span6 offset3">
<%= form_for(:session, url: sessions_path) do |f| %>

  <%= f.label :email %>
  <%= f.text_field :email %>

  <%= f.label :password %>
  <%= f.password_field :password %>

  <%= f.submit "Sign in", class: "btn btn-large btn-primary" %>
<% end %>

<p>New user? <%= link_to "Sign up now!", signup_path %></p>
</div>
</div>

会话控制器

class SessionsController < ApplicationController

def new
end

def create
user = User.find_by(email: params[:session][:email].downcase)
if user && user.authenticate(params[:session][:password])
  sign_in user
  redirect_to user
else
  flash.now[:error] = 'Invalid email/password combination'
  render 'new'
end
end

def destroy
end
end

我的用户控制器

class User < ActiveRecord::Base
attr_accessible :first, :last, :email, :password, :password_confirmation
has_secure_password

before_save { self.email = email.downcase }
before_create :create_remember_token
validates :first, :last, presence: true, length: { maximum: 50 }
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[andover]+\.[edu]+\z/i
validates :email, presence:   true,
                format:     { with: VALID_EMAIL_REGEX },
                uniqueness: { case_sensitive: false }
validates :password, length: { minimum: 6 }

has_and_belongs_to_many :order
has_many :orders_users

def User.new_remember_token
SecureRandom.urlsafe_base64
end

def User.encrypt(token)
Digest::SHA1.hexdigest(token.to_s)
end

private

def create_remember_token
  self.remember_token = User.encrypt(User.new_remember_token)
end
end

会话助手

module SessionsHelper

def sign_in(user)
remember_token = User.new_remember_token
cookies.permanent[:remember_token] = remember_token
user.update_attribute(:remember_token, User.encrypt(remember_token))
self.current_user = user
end

def signed_in?
!current_user.nil?
end

def current_user=(user)
@current_user = user
end

def current_user
remember_token = User.encrypt(cookies[:remember_token])
@current_user ||= User.find_by(remember_token: remember_token)
end

end

标题代码

<header class="navbar navbar-fixed-top navbar-inverse">
<div class="navbar-inner">
<div class="container">
  <%= link_to "sample app", root_path, id: "logo" %>
  <nav>
    <ul class="nav pull-right">
      <li><%= link_to "Home", root_path %></li>
      <li><%= link_to "Help", help_path %></li>
      <% if signed_in? %>
        <li><%= link_to "Users", '#' %></li>
        <li id="fat-menu" class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown">
            Account <b class="caret"></b>
          </a>
          <ul class="dropdown-menu">
            <li><%= link_to "Profile", current_user %></li>
            <li><%= link_to "Settings", '#' %></li>
            <li class="divider"></li>
            <li>
              <%= link_to "Sign out", signout_path, method: "delete" %>
            </li>
          </ul>
        </li>
      <% else %>
        <li><%= link_to "Sign in", signin_path %></li>
      <% end %>
    </ul>
  </nav>
</div>
</div>
</header>

这是注册页面

<% provide(:title, 'Sign up') %>
<h1>Sign up</h1>

<div class="row">
<div class="span6 offset3">
<%= form_for(@user) do |f| %>
    <%= render 'shared/error_messages' %>

    <%= f.label :first %>
    <%= f.text_field :first %>

    <%= f.label :last %>
    <%= f.text_field :last %>

    <%= f.label :email %>
    <%= f.text_field :email %>

    <%= f.label :password %>
    <%= f.password_field :password %>

    <%= f.label :password_confirmation, "Confirmation" %>
    <%= f.password_field :password_confirmation %>

  <%= f.submit "Create my account", class: "btn btn-large btn-primary" %>
<% end %>
</div>
</div>

我想这就是我能给你的所有可能信息。我可以给你我的其他规格,但我通过了那些,所以我认为那很愚蠢。无论如何,你们中的任何人都知道出了什么问题吗?

编辑:Rake 路由命令。

  Prefix Verb   URI Pattern               Controller#Action
  users GET    /users(.:format)          users#index
        POST   /users(.:format)          users#create
new_user GET    /users/new(.:format)      users#new
edit_user GET    /users/:id/edit(.:format) users#edit
   user GET    /users/:id(.:format)      users#show
        PATCH  /users/:id(.:format)      users#update
        PUT    /users/:id(.:format)      users#update
        DELETE /users/:id(.:format)      users#destroy
sessions POST   /sessions(.:format)       sessions#create
new_session GET    /sessions/new(.:format)   sessions#new
session DELETE /sessions/:id(.:format)   sessions#destroy
   root GET    /                         static_pages#home
 signup GET    /signup(.:format)         users#new
 signin GET    /signin(.:format)         sessions#new
signout DELETE /signout(.:format)        sessions#destroy
   help GET    /help(.:format)           static_pages#help
  about GET    /about(.:format)          static_pages#about
contact GET    /contact(.:format)        static_pages#contact

【问题讨论】:

  • 好像找不到app/views/sessions/new.html.erb。您确定该文件确实存在吗?可能是名称中的类型或其他内容

标签: ruby-on-rails


【解决方案1】:

对于那些错误,它只是说它找不到带有这些处理程序的视图文件,

介意我看看你的结果

rake routes

命令?

我假设您没有任何其他规范调用

visit signin_path

【讨论】:

  • rake routes 命令结果已在上面发布。这能帮助你找出我的问题吗? 手指交叉
  • 你能去你的 localhost:3000/signin 吗?页面加载正常?
  • 没有。我以前可以,但后来我开始添加东西,这个问题就出现了。
  • 我建议 SourceTree 让 Git 恢复到它工作的状态,检查您的更改并尝试放大任何文件重命名以及控制器和路由文件更改! :0
猜你喜欢
  • 1970-01-01
  • 2016-11-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-14
  • 2016-05-26
相关资源
最近更新 更多