Tag: railstutorial.org

Rails教程(M.Hartl)第3版,第8章,如何通过关闭流氓`rails console`来解锁数据库?

我在第8.4.1章中 ,在生成迁移后我尝试运行: $ bundle exec rake db:migrate 但是给出了以下错误: rake aborted! StandardError: An error has occurred, this and all later migrations canceled: SQLite3::BusyException: database is locked: #followed by a long list of paths/filenames and line numbers… 我知道这可能是因为我没有正确退出rails console –sandbox会话而退出终端。 但是如何找到并关闭此rails console会话?

Rails教程:RSpec测试解耦

我正在尝试在Michael Hartl的Ruby on Rails教程中 进行第8.5章练习2 。 演习如下: 按照第8.3.3节中的示例,浏览用户和身份validation请求规范(即当前在spec / requests目录中的文件)并在spec / support / utilities.rb中定义实用程序函数,以将测试与实现分离。 额外功劳:将支持代码组织到单独的文件和模块中,并通过在规范帮助文件中正确包含模块来使一切工作正常。 例8.3.3:utilities.rb include ApplicationHelper 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| page.should have_selector(‘div.alert.alert-error’, text: message) end end 定义的valid_signin(user)函数在authentication_pages_spec.rb的以下块中使用,并且工作正常。 describe “with valid information” do let(:user){FactoryGirl.create(:user)} before { valid_signin(user) […]

Ruby(on Rails)语法

我正在回顾“Ruby on Rails 3 Tutorial”并试图在更深层次上理解语法。 以下是我定义的辅助操作的一些示例代码: module ApplicationHelper def title base_title = “Mega Project” if @title.nil? base_title else “#{base_title} | #{@title}” end end end 我的问题是: “#{base_title} | #{@title}” 这条线的结构究竟发生了什么? 在更高的层面上,查找这样的东西的首选来源在哪里?

RailsTutorial.org – 用户中的ExecJS :: RuntimeError #index

我正在关注Michael Hartl的Ruby on Rails教程,在第二章中,我们设置了一个演示应用程序。 我遇到了错误,我无法找到原因! 我确保遵循教程中的每个命令: Ran rails new to demo_app创建项目 根据需要更新了gem文件 执行rails generate scaffold User name:string email:string 使用bundle exec rake db:migrate 启动服务器 – rails s http://localhost:3000/显示正确 当我尝试导航到http://localhost:3000/users/ ,出现此错误 任何人都可以了解设置为什么会起作用?!

Ruby on Rails Michael Hartl第8.5章测试失败

我已经看到了另一个问题,其中current_user变量被定义了两次。 我的代码中有相同的错误,但删除current_user的第二个定义仍然无法解决我收到的错误消息。 这是我在运行测试时得到的错误消息: 1) Failure: SessionsHelperTest#test_current_user_returns_right_user_when_session_is_nil [/home/ubuntu/workspace/sample_app/test/helpers/sessions_helper_test.rb:11]: — expected +++ actual @@ -1 +1 @@ -# +nil 这是我的sessions_helper文件: module SessionsHelper #logs in the given user def log_in(user) session[:user_id] = user.id end #remembers a user in a persistent session def remember(user) user.remember cookies.permanent.signed[:user_id] = user.id cookies.permanent[:remember_token] = user.remember_token end #returns current logged in user #def current_user […]

Rails教程第10.3.3章 – 4 RSpec错误(应用程序工作)

我得到4个RSpec错误与Will-Paginategem有关,但对于我的生活,我无法弄清楚他们指的是什么。 该应用程序工作正常。 Failures: 1) UsersController GET ‘index’ for signed-in users should be successful Failure/Error: get :index NoMethodError: undefined method `paginate’ for # # ./app/controllers/users_controller.rb:7:in `index’ # ./spec/controllers/users_controller_spec.rb:30:in `block (4 levels) in ‘ 2) UsersController GET ‘index’ for signed-in users should have the right title Failure/Error: get :index NoMethodError: undefined method `paginate’ for # # ./app/controllers/users_controller.rb:7:in […]

在Hartl的rails教程的步骤5.1.2中,bootstrap-sass gem破坏了我的轨道3.2.3

到目前为止,一切都很好,包括上传到github和heroku,以及使用postgres进行dev / test和prod / heroku。 我一添加 gem’bootstrap-sass’,’2.0.0′ 我的Gemfile并运行bundle install (或bundle install –without assets ),spork,guard和rails(以及独立乘客)都抱怨以下内容: /var/lib/rails/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/lib/bundler/runtime.rb:74:in `require’: cannot load such file — bootstrap/sass (LoadError) from /var/lib/rails/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/lib/bundler/runtime.rb:74:in `rescue in block in require’ from /var/lib/rails/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/lib/bundler/runtime.rb:62:in `block in require’ from /var/lib/rails/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/lib/bundler/runtime.rb:55:in `each’ from /var/lib/rails/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/lib/bundler/runtime.rb:55:in `require’ from /var/lib/rails/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/lib/bundler.rb:119:in `require’ from /var/lib/rails/sample_app/config/application.rb:13:in `’ from /var/lib/rails/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/commands.rb:53:in `require’ from /var/lib/rails/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/commands.rb:53:in `block in ‘ […]

Rails找不到已安装的gem

我正在关注专门要求4.2.0版本的Rails教程,所以我安装了带有sudo gem install rails -v 4.2.0 Rails,它运行正常。 当我尝试使用rails _4.2.0 new test_app创建一个新的应用程序时,我收到一条错误消息,上面写着/Library/Ruby/Site/2.0.0/rubygems/dependency.rb.315: in ‘to_specs’: Could not find ‘railties’ (=4.2.0) – did find: [railties-4.2.1] (Gem::LoadError)并继续进行一点点。 我已经尝试使用sudo gem install railties -v 4.2.0安装特定版本的railties ,但我仍然得到相同的错误。 是在两个不同的地方检查/安装gem? 编辑:运行gem list产生以下输出,清楚地显示railties (4.2.0) : *** LOCAL GEMS *** actionmailer (4.2.0) actionpack (4.2.1, 4.2.0) actionview (4.2.1, 4.2.0) activejob (4.2.1, 4.2.0) activemodel (4.2.0) activerecord (4.2.0) activesupport […]

RoR教程第4.1.1章,混淆了为什么标题助手不会失败

我正在阅读Michael Hartl的Ruby on Rails 3.2教程,我很困惑为什么第4.1.1节中找到的标题助手不会失败。 他谈到在你从视图中省略这段代码时需要一个标题助手: 但是在应用程序布局文件中有以下行: 是不是将nil值传递给full_title助手,因为提供者没有为:title符号设置值? 在本章的后面,他有一个键入rails控制台的示例,它与full_title函数相同: def string_message(string) if string.empty? “It’s an empty string!” else “The string is nonempty.” end end 这使我更加困惑。 在控制台,如果我输入: string_message(“”)然后我得到”It’s an empty string!” string_message(“something”)然后我得到”The string is nonempty.” string_message(nil)然后我得到NoMethodError: undefined method ’empty?’ for nil:NilClass NoMethodError: undefined method ’empty?’ for nil:NilClass string_message(test)然后我得到ArgumentError: wrong number of arguments (0 for 2..3) string_message(:test)然后我得到”The […]

密码validation在两个相反的情况下失败

我正在研究Michael Hartl的Ruby on Rails教程,并产生了一个有趣的困境。 我会做错事,所以我需要你帮忙找到问题。 该问题围绕User模型中的密码属性validation。 该属性的初始validation是: validates :password, presence: true, confirmation: true, length: { minimum: 6 } 这需要最小长度的密码,旨在满足新用户创建其实例的情况。 我已经创建了以下测试(我希望我使用过Rspec!)。 这些测试检查validation是否有效: test “password must not be blank or made up of spaces” do @user.password = @user.password_confirmation = ” ” assert_not @user.valid? end test “password must not be empty/nil” do @user.password = @user.password_confirmation = “” assert_not […]