在我的系统中,用户通过rails网站注册.我必须使用ruby编写的自定义应用程序服务器对用户进行身份验证.
错误消息:
You must activate the Authlogic::Session::Base.controller with a controller object before creating objects (Authlogic::Session::Activation::NotActivatedError)
Run Code Online (Sandbox Code Playgroud) 我有一个如下控制器:
namespace :admin do
resources :posts
end
# app/controllers/admin_posts_controller.rb
module Admin
class PostsController < ApplicationController
end
end
Run Code Online (Sandbox Code Playgroud)
问题是我不知道Admin::PostsControllerTest去哪儿了.
我期待以下作品:
# test/functional/admin/posts_controller_test.rb
module Admin
class PostsControllerTest < ActionController::TestCase
end
end
Run Code Online (Sandbox Code Playgroud)
但是,如果我这样做,运行时会出现以下错误rake test:functionals:
RuntimeError: @controller is nil: make sure you set it in your test's setup method.
Run Code Online (Sandbox Code Playgroud) 该大厦局部对象,分步页面上的妖兽宝石百科解释了如何创建一个脚印与对象的步骤wicked。
但是我必须如何创建一个新Product对象?
我必须在 的新动作中这样做ProductsController吗?我必须重定向到哪里?
在我的Rails开发环境中工作,一切都很好,然后去吃午餐,现在我在浏览器中得到"文件结束"错误.有谁知道发生了什么?
来自curl的回复相同:
$ curl http://localhost:7000
EOFError at /
=============
> end of file reached
app/views/application/_javascript.html.slim, line 1
---------------------------------------------------
``` ruby
> 1 = javascript_include_tag :application
2
3 = yield :javascript
4
```
App backtrace
-------------
- app/views/application/_javascript.html.slim:1:in `_app_views_application__javascript_html_slim__3196685002532601281_70250473343220'
- app/views/layouts/full_width.html.slim:24:in `_app_views_layouts_full_width_html_slim___489443475469111239_70110396332180'
- app/controllers/home_controller.rb:6:in `index'
Full backtrace
--------------
- activesupport (4.1.9) lib/active_support/core_ext/marshal.rb:6:in `load_with_autoloading'
- sprockets (2.11.0) lib/sprockets/cache/file_store.rb:19:in `block in []'
- sprockets (2.11.0) lib/sprockets/cache/file_store.rb:19:in `[]'
- sprockets (2.11.0) lib/sprockets/caching.rb:14:in `cache_get'
- sprockets (2.11.0) lib/sprockets/caching.rb:84:in `cache_get_hash'
- sprockets (2.11.0) lib/sprockets/caching.rb:54:in `cache_asset'
- …Run Code Online (Sandbox Code Playgroud) 每次我尝试使用"script/runner -e production ClassName.run"从我的rails 2.2 app的lib目录运行任何类时,我收到以下错误:
/usr/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/commands/runner.rb:47:
/usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:89:in `const_missing': uninitialized constant ClassName (NameError)"
Run Code Online (Sandbox Code Playgroud)
出于某种原因,当我运行它,因为我没有得到这个错误test,而不是production,和一切工作正常.
O是的,run是一种类方法,即def self.run .... end
有什么建议?
我运行一个测试的RSpec以确保两种模式之间相互关联has_many和belongs_to.这是我的测试.
describe "testing for has many links" do
before do
@post = Post.new(day: "Day 1", content: "Test")
@link = Link.new(post_id: @post.id, title: "google", url: "google.com")
end
it "in the post model" do
@post.links.first.url.should == "google.com"
end
end
Run Code Online (Sandbox Code Playgroud)
测试告诉我url是一个未定义的方法.我的考试有什么问题?或者我只是错过了一些基本的东西.
Post的模型文件
has_many :links
Run Code Online (Sandbox Code Playgroud)
链接的模型文件
belongs_to :post
Run Code Online (Sandbox Code Playgroud)
最重要的是,链接模型具有属性 post_id
我正在为rspec测试创建一个示例应用程序,我按照以下步骤 在Gemfile中:
gem "rspec-rails", :group => [:test, :development]
group :test do
gem "factory_girl_rails"
gem "capybara"
gem "guard-rspec"
end
Run Code Online (Sandbox Code Playgroud)
然后执行以下步骤:
在我的spec_helper文件中添加了"require capybara/rspec"
创建了一个样本测试,如下所示:
require 'spec_helper'
describe "Users" do
describe " List users" do
it "List all users" do
get users_path
page.has_content?('List Users')
end
end
end
Run Code Online (Sandbox Code Playgroud)
但它不起作用,得到以下错误
undefined local variable or method `page'
Run Code Online (Sandbox Code Playgroud)
*我怀疑我没有正确配置水豚,让我知道配置水豚的正确方法.
我有一个规范,用于在禁用缓存和启用缓存时测试操作缓存。看起来测试执行的顺序会影响它们是否通过。
it "should not cache the index page when we're not caching" do
ActionController::Base.perform_caching = false
HomeController.caches_action :index
Rails.cache.clear
ActionController::Base.cache_store.exist?(:index_cache_path).should be_false
get :index
ActionController::Base.cache_store.exist?(:index_cache_path).should be_false
end
it "should cache the index page when we're caching" do
ActionController::Base.perform_caching = true
HomeController.caches_action :index
Rails.cache.clear
ActionController::Base.cache_store.exist?(:index_cache_path).should be_false
get :index
ActionController::Base.cache_store.exist?(:index_cache_path).should be_true
end
Run Code Online (Sandbox Code Playgroud)
当按上述顺序运行测试时,最后一个测试会失败,因为最后一个期望中不存在cache_store。我很困惑为什么无缓存测试会影响缓存测试。有谁知道出了什么问题吗?
我正在使用ruby标准记录器,我想每天轮换一次,所以在我的代码中我有:
Logger.new("#{$ROOT_PATH}/log/errors.log", 'daily')
Run Code Online (Sandbox Code Playgroud)
它工作得很好,但它创建了两个文件errors.log.20130217和errors.log.20130217.1.
我如何强制它每天只创建一个文件?
我是新手ruby on rails。我想知道如何连接Sql server到 Rails 应用程序。
我正在 Windows 环境中使用 RoR。SQL ServerROR 中有建立连接的链接吗?
ruby ×5
rspec ×2
associations ×1
authlogic ×1
capybara ×1
controller ×1
debugging ×1
eof ×1
javascript ×1
logging ×1
rspec-rails ×1
sql ×1
sql-server ×1
tdd ×1
testing ×1