签名缺少模板

时间:2014-01-26 04:29:27

标签: ruby-on-rails

最后经过大约两个小时搞乱这件事后,我已经弄明白了7个错误中的大多数。也就是说,我有一个新的,我不知道如何摆脱它。我似乎遇到了与我提出的类似问题相同的问题,那是在我开始使用我最近的git提交之前。不用说,我现在不开心。无论如何,这是失败:

1) Authentication signin with valid information followed by signout 
 Failure/Error: before { click_link "Sign out" }
 ActionView::MissingTemplate:
   Missing template sessions/destroy, application/destroy with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee]}. Searched in:
     * "/Users/Brawain/rails_projects/sample_app/app/views"
 # ./spec/requests/authentication_pages_spec.rb:45:in `block (5 levels) in <top (required)>'

我实际上不知道需要什么代码,所以我会发布所有会话内容以及给我带来麻烦的规范。

身份验证规范

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') }
end

describe "signin" do
before { visit signin_path }

describe "with invalid information" do
  before { click_button "Sign in" }

  it { should have_title('Sign in') }
  it { should have_selector('div.alert.alert-error') }

  describe "after visiting another page" do
    before { click_link "Home" }
    it { should_not have_selector('div.alert.alert-error') }
  end
end

describe "with valid information" do
    let(:user) { FactoryGirl.create(:user) }   

    before do
        visit '/signin'
        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) }

    describe "followed by signout" do
        before { click_link "Sign out" }
        it { should have_link('Sign in') }
    end
end
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

def destroy
sign_out
redirect_to root_url
end

def sign_out
current_user.update_attribute(:remember_token,
                              User.encrypt(User.new_remember_token))
cookies.delete(:remember_token)
self.current_user = nil
end
end

会话控制器

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

节/ 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>

这不是整个页面,但这是我的身体html代码。我把它包括在内,因为它有相关的链接。

<div id="announcements">
    TESTER TIME!    
        <% 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 %>

</div>

1 个答案:

答案 0 :(得分:0)

你需要在destroy函数中销毁会话然后如果你不想显示任何注销屏幕,那么redirect_to root_path

大部分人在注销后重定向