Tag: railstutorial.org

rails generate – “找不到生成器”

我正在关注Michael Hartl的Ruby on Rails教程。 在6.3.1节中,我尝试生成一个迁移文件,以便将Password字段添加到我的用户模型中。 这是我运行的代码: rails generate add_passsword_digest_to_users password_digest:string 但这会引发错误: Could not find generator add_passsword_digest_to_users. 我之前使用过rails generate命令,它完美地运行了。 我不知道为什么我现在遇到这个问题。 版本:Rails 3.2.8,ruby 1.9.3p194(2012-04-20修订版35410)[x86_64-linux]

为Heroku安装PostgreSQL gem pq

这里的第一个问题,但我现在非常感谢你,因为stackoverflow在michael hartl tut的第一章中帮了我近15次。 现在我正在尝试使用此命令安装PostgreSQL(pg gem): ` group :production do gem ‘pg’, ‘0.15.1’ gem ‘rails_12factor’, ‘0.0.2’ end` 但它显示出错误 -bash: group: command not found 然后我尝试直接安装(?)gem gem install pg 但它显示了另一个错误 `Fetching: pg-0.17.1.gem (100%) Building native extensions. This could take a while… ERROR: Error installing pg: ERROR: Failed to build gem native extension. rvm/rubies/ruby-2.0.0-p353/bin/ruby extconf.rb checking for pg_config… no […]

Rails教程Ch。 9练习6:预期的响应为,但

我正在尝试编写测试和应用程序代码,以便在已尝试创建用户或访问新用户路径时重定向已登录到root_path的用户。 以下是我在user_pages_spec.rb中编写的测试: describe “for signed in users” do let(:user) { FactoryGirl.create(:user) } before { sign_in user } describe “using a ‘new’ action” do before { get new_user_path } specify { response.should redirect_to(root_path) } end describe “using a ‘create’ action” do before { post users_path } specify { response.should redirect_to(root_path) } end end UsersController: class UsersController […]

Rails教程sample_app在Heroku中失败,带有log:ActionController :: RoutingError(没有路由匹配“/ about”):

我正在关注Rails教程的在线版本。 第3章中的Sample_app在本地工作正常,但是当推送到Heroku时,会找到主页,但不会找到其他页面。 尝试查看“关于”页面后运行heroku日志会给我(以及其他许多内容)上面的错误: 2015-08-09T02:56:43.916991+00:00 app[web.1]: ActionController::RoutingError (No route matches [GET] “/about”): 我的routes.rb文件是 Rails.application.routes.draw do root ‘static_pages#home’ get ‘static_pages/help’ get ‘static_pages/about’ end 我仔细地按照指示行事。 我尝试删除并重新创建Heroku文件。 我做了网络搜索,尝试了一些无济于事的事情。 我的gemfile直接来自本书的在线版本,该版本使用当前版本。 解决了: #thedanotto让我运行heroku run rake routes ,显示帮助和关于页面被定向到{root} / static_pages / about而不是{root} / about。 我仍然感到困惑,为什么教程给出了关于路线,看起来没有按预期工作,并欢迎任何进一步的评论,但我将此标记为已解决。

Rspec错误,“nil的未定义方法’downcase’:NilClass”

我在运行Rspec测试时不断收到此错误,但无法弄清楚原因。 我对Rails(以及一般的编程)都很陌生,所以任何方向或帮助都会非常感激! 编辑:这是一个回购链接,如果有人想筛选和/或复制错误。 https://github.com/FluxAnimus/sample_app/tree/sign-up Failures: 1) User pages profile page Failure/Error: before { visit user_path(user) } ActionView::Template::Error: undefined method `downcase’ for nil:NilClass # ./app/helpers/users_helper.rb:5:in `gravatar_for’ # ./app/views/users/show.html.erb:3:in `_app_views_users_show_html_erb__1766857043046396980_38603940′ # ./spec/requests/user_pages_spec.rb:9:in `block (3 levels) in ‘ 2) User pages profile page Failure/Error: before { visit user_path(user) } ActionView::Template::Error: undefined method `downcase’ for nil:NilClass # ./app/helpers/users_helper.rb:5:in `gravatar_for’ […]

使用Capybara / Rspec使用will_paginate Gem测试视图

做Michael Hartl的Rails教程, 第10章,第5节,练习2 。 我 – 非常简单 – 尝试编写测试以确保使用will_paginate gem在几页上出现分页div(这似乎是Hartl测试分页是否有效的首选方法),但是当我添加以下代码时… subject { page } . . . it { should have_selector(‘div.pagination’) } ..it返回.. 1) UserPages profile page Failure/Error: it { should have_selector(‘div.pagination’) } expected css “div.pagination” to return something 这特别奇怪,因为在这个特定的_spec文件中,这个相同的Rspec代码在一些测试中传递而在其他测试中失败(我将在下面强调这一点)。 pagination div也存在于浏览器的源代码中,当然它工作正常。 因为它在某些地方而不是在其他地方失败,我得假设这是某种“范围” – 或与will_paginate相关的分配类型问题 – 你看,对于失败的测试,被分页的内容实际上是“ Microposts“控制器,但正在测试的页面/视图由”用户“控制器处理。 对于通过测试,视图和控制器都是“用户”。 这可能是问题吗? 我的FactoryGirl设置/调用也可能被破坏,并且由于某种原因没有在测试中触发分页代码。 我是一个Rails n00b – 实际上是编程的新手 […]

尝试设置亚马逊的S3存储桶:403禁止错误和设置权限

我正在关注Hartl的railstutorial.org并且已经到了11.4.4:生产中的图像上传 。 我做了什么: 注册amazon web services 在Amazon Identity and Access Management中,我创建了一个用户。 用户已成功创建。 在Amazon S3中,我创建了一个新存储桶。 设置新存储桶的权限: 权限:本教程指示“授予对上一步中创建的用户的读写权限”。 但是,在存储桶的“Permissons”下,未提及新用户的名称。 我只能选择Everyone,Authenticated用户,Log delivery,Me和用户名,亚马逊似乎已经从我的名字+数字创建了自己。 我通过选择Authenticated用户并选中了上传/删除和查看权限(而不是选择列表和编辑权限)框来尝试它。 我也通过选择Everyone并检查所有四个框来尝试它。 结果是一样的。 我按照本教程的说明在我的Rails应用程序中实现(我不相信那里有任何错误,所以我没有在这里包含这些步骤,以免使它太长)。 初始化程序carrier_wave.rb设置为以下代码。 我已经添加了region: ‘eu-west-1’到初始化器(我从这里得到的一个想法)来摆脱connecting to the matching region will be more performant的消息connecting to the matching region will be more performant 。 if Rails.env.production? CarrierWave.configure do |config| config.fog_credentials = { # Configuration for Amazon […]

如何保持rspec测试DRY有很多“have_link”

我是Ruby on Rails的新手,我现在正在做http://ruby.railstutorial.org 。 根据我的理解,该语言应该严格遵循这个DRY标准,但在本教程中涉及到测试驱动开发时,它是如此WET。 例如 it { should have_link(‘Users’, href: users_path) } it { should have_link(‘Profile’, href: user_path(user)) } it { should have_link(‘Settings’, href: edit_user_path(user)) } it { should have_link(‘Sign out’, href: signout_path) } 在这里,我们有很多行几乎看起来一样。 我试过这个 it “should have following links from this array” do [ [‘Users’, href: users_path], [‘Profile’, href: user_path(user)], [‘Settings’, href: […]

适用于使用carrierwave上传图像文件的用户的s3权限

在Michael Hartl的The Rails Tutorial的第11章末尾,我成功地设法通过创建存储桶,使用IAM设置用户并授予用户AmazonS3FullAccess策略来启用用户上传到Amazons S3服务。 让我的网站上的未知用户可以完全访问我的网站上的图像上传桶并且我不确定我是否应该这样感觉,这感觉很脏并且非常不安全。 我创建了一个自定义策略 http://awspolicygen.s3.amazonaws.com/policygen.html 以下是: { “版本”:“2012-10-17”, “声明”:[ { “Sid”:“Stmt1445501067518”, “行动”:[ “S3:GetObject的”, “S3:PutObject” ] “效果”:“允许”, “资源”:“arn:aws:s3 ::: bucketname” } ] } 我对我的解决方案没有信心,也无法找到任何答案谷歌搜索最佳方式。 我正在使用carrierwave(有意使用carrierwave_direct用于我自己的项目),雾和mini_magickgem。

Railsvalidation错误消息显示错误消息和数组

我正在完成Ruby-on-Rails3教程第8章。 我创建了一个用户提交注册站点的表单。 validation在模型中设置。 它们已经过测试并正在运行。 问题是,当我显示validation错误消息时,执行以下操作: prohibited this user from being saved: There were problems with the following fields: 我不仅获得了validation消息,而且还显示了实际的数组: 2 errors prohibited this user from being saved: There were problems with the following fields: Password can’t be blank Password is too short (minimum is 6 characters) **[“Password can’t be blank”, “Password is too short (minimum […]