小编Han*_*nna的帖子

失败:预期 0 在 ruby​​ on rails 上 >= 1

我正在做 Hartle 教程,每次运行 rake 测试时都会看到此失败,我看到此失败:

  1) Failure:
StaticPagesControllerTest#test_should_get_help [.../sample_app/test/controllers/static_pages_controller_test.rb:14]:
<Help | Ruby on Rails Tutorial Sample App> expected but was
<Ruby on Rails Tutorial Sample App>..
Expected 0 to be >= 1.
Run Code Online (Sandbox Code Playgroud)

这是什么意思?我该如何解决?这是我的 static_pages_controller_test.rb 文件。

require 'test_helper'

class StaticPagesControllerTest < ActionController::TestCase

  test "should get home" do
    get :home
    assert_response :success
    assert_select "title", "Ruby on Rails Tutorial Sample App"   end

  test "should get help" do
    get :help
    assert_response :success
    assert_select "title", "Help | Ruby on Rails Tutorial Sample App"   end

  test …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails railstutorial.org

6
推荐指数
1
解决办法
2587
查看次数

rake db:seed验证失败

我正在做hartle教程的第12章.我跑的时候遇到bundle exec rake db:seed了这个错误:

ActiveRecord::RecordInvalid: Validation failed: Email has already been taken
Run Code Online (Sandbox Code Playgroud)

我试着跑步

rake db:reset
rake db:migrate
rake db:test:prepare
Run Code Online (Sandbox Code Playgroud)

最后

rake db:populate 
Run Code Online (Sandbox Code Playgroud)

但他们没有解决问题.当我运行rake db:populate它时给出:

Don't know how to build task 'db:populate'
Run Code Online (Sandbox Code Playgroud)

这是我的seeds.rb文件:

    # Users
User.create!(name:  "Example User",
             email: "example@railstutorial.org",
             password:              "foobar",
             password_confirmation: "foobar",
             admin:     true,
             activated: true,
             activated_at: Time.zone.now)

99.times do |n|
  name  = Faker::Name.name
  email = "example-#{n+1}@railstutorial.org"
  password = "password"
  User.create!(name: name,
              email: email,
              password:              password,
              password_confirmation: password,
              activated: true,
              activated_at: Time.zone.now)
end

# Microposts …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails railstutorial.org

5
推荐指数
1
解决办法
5444
查看次数

GCC在以前工作正常的代码上出错

我有一个程序已经成功编译过去,但现在我得到了一堆错误.源代码只是:

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>

int main()
{
    int fd;
    fd = creat("datafile.dat", S_IREAD | S_IWRITE);
    if (fd == -1)
        printf("Error in opening datafile.dat\n");
    else
    {
        printf("datafile.dat opened for read/write access\n");
        printf("datafile.dat is currently empty\n");
    }
    close(fd);
    exit (0);
}
Run Code Online (Sandbox Code Playgroud)

现在我得到了错误:

cre.C:8:54: error: ‘creat’ was not declared in this scope
cre.C:16:17: error: ‘close’ was not declared in this scope
cre.C:17:16: error: ‘exit’ was not declared in this scope
Run Code Online (Sandbox Code Playgroud)

有时候我会收到一个错误gxx_personality_v0,有时我根本就没有错误!我尝试过更新gcc,但问题仍然存在.出了什么问题?在Vaio笔记本电脑上的OS UBUNTU 12.1

filenames gcc

0
推荐指数
1
解决办法
227
查看次数

rails NoMethodError:nil的未定义方法"":NilClass

我正在研究迈克尔哈特尔的导轨教程(第9章).

我收到此错误:

 Error:
UsersLoginTest#test_login_with_remembering:
NoMethodError: undefined method `FILL_IN' for nil:NilClass
    test/integration/users_login_test.rb:42:in `block in <class:UsersLoginTest>'
Run Code Online (Sandbox Code Playgroud)

FILL-IN在第8章中添加了,直到第9章才有任何问题.我尝试了很多,但我无法修复它.这是我的UsersLoginTest类.

class UsersLoginTest < ActionDispatch::IntegrationTest

  def setup
    @user = users(:michael)
  end

  test "login with invalid information" do
    get login_path
    assert_template 'sessions/new'
    post login_path, session: { email: "", password: "" }
    assert_template 'sessions/new'
    assert_not flash.empty?
    get root_path
    assert flash.empty?
  end

  test "login with valid information followed by logout" do
       get login_path
    post login_path, session: { email: @user.email, password: 'password' }
    assert is_logged_in?
    assert_redirected_to …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails nomethoderror railstutorial.org

0
推荐指数
1
解决办法
1873
查看次数

在流明中找不到特征'App \ HasApiTokens'

我正在运行流明(5.6.3)(Laravel组件5.6。*)。我正在尝试使用本教程(https://www.youtube.com/watch?v=eWoJ2YbdrWU&t=5s)构建Rest API 。这是我的games.php代码:

<?php 

namespace App;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Database\Eloquent\SoftDeletes;
use Bican\Roles\Traits\HasRoleAndPermission;
use Bican\Roles\Contracts\HasRoleAndPermission as HasRoleAndPermissionContract;

use Illuminate\Database\Eloquent\Model;

class games extends Model implements AuthenticatableContract, AuthenticatableContract, HasRoleAndPermissionContract
{ 
    use HasApiTokens, Authenticatable, Authorizable;
    protected $table="games";

    protected $fillable = ['Team 1','Team 2','Score 1','Score 2','Game Date','Viewers'];     
}
Run Code Online (Sandbox Code Playgroud)

运行后出现的错误是:

PHP Fatal error:  Trait 'App\HasApiTokens' not found in C:\Users...lumen-api\app\games.php on line 14

Fatal error: Trait 'App\HasApiTokens' not found in C:\Users\...lumen-api\app\games.php on line 14

In games.php line 14:

  Trait 'App\HasApiTokens' not found
Run Code Online (Sandbox Code Playgroud)

我所做的一切与本教程相同。我无法在第2部分中解决此错误。

php traits lumen

0
推荐指数
1
解决办法
4932
查看次数