railstutorial.org

ruby on rails tutorial section 3.2 rspec testing error

橙三吉。 提交于 2019-12-03 17:10:34
recently started the RoRTute by Michael Hartl, getting stuck trying my first rspec test in section 3.2, at this point the test is meant to fail but all i get are errors which I'm having a hard time interpreting. I've had a look around but not getting much luck finding a similar error and/or solution. I am brand new to programming and ruby/rails. Any help would be greatly appreciated, thank you! terminal error output Macintosh:sample_app rails$ bundle exec rspec spec/requests/static_pages_spec.rb /Users/rails/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/selenium-webdriver-2.0.0/lib

Rails Tutorial: SQLite3::ConstraintException: UNIQUE constraint failed: users.email

巧了我就是萌 提交于 2019-12-03 11:31:19
I'm following along with the rails tutorial. I'm on ch. 6 and I'm getting a strange error with SQLite3 (for the record, I'm using sqlite version 1.3.10 and the tutorial uses 1.3.9) I don't get an error when I run rake db:migrate, but when I run the migration for the test environment, here's what I get: $ bundle exec rake test:models rake aborted! ActiveRecord::PendingMigrationError: Migrations are pending. To resolve this issue, run: bin/rake db:migrate RAILS_ENV=test sample_app/test/test_helper.rb:3:in `<top (required)>' sample_app/test/models/user_test.rb:1:in `require' sample_app/test

In Rails, how do you destroy a session when a browser is closed?

删除回忆录丶 提交于 2019-12-03 11:17:16
问题 I'm going through Michael Hartl's Railstutorial and I am stuck on Exercise 9.6.2. I searched online and used this code in my Sessions Helper: module SessionsHelper def sign_in(user) session[:user_id] = user.id self.current_user = user end def current_user=(user) @current_user = user end def current_user @current_user ||= User.find(session[:user_id]) if session[:user_id] end def signed_in? !current_user.nil? end def sign_out session[:user_id] = nil self.current_user = nil end end I found it

$ bundle exec rake db:reset command raising couldn't drop db/development.sqlite3

十年热恋 提交于 2019-12-03 08:37:46
问题 I tried to run $ bundle exec rake db:reset and found the following on console Couldn't drop db/development.sqlite3 : #<Errno::EACCES: Permission denied - c:/sample_app/db/development.sqlite3> db/development.sqlite3 already exists -- create_table("users", {:force=>true}) -> 0.3940s -- add_index("users", ["email"], {:name=>"index_users_on_email", :unique=>true}) -> 0.1280s -- initialize_schema_migrations_table() -> 0.0010s -- assume_migrated_upto_version(20120419034627, ["c:/sample_app/db

Do I need a “Users” controller when using Devise in Rails

丶灬走出姿态 提交于 2019-12-03 07:54:59
问题 I am a Rails newbie. I am working on a small Rails4 project trying to improve my skills. I am loosely following M.Hartl's tutorial. As per the tutorial a custom user authentication is built. However I would like to use Devise for User authentication. Do I still need to have a Users controller as in the tutorial? In which cases should I use/not use a Users controller when already using Devise? Concerning the tutorial, do I just skip the controller generating part or do I have to map the

Rails — create and create! methods, RoR 3 Tutorial

折月煮酒 提交于 2019-12-03 06:30:31
问题 So I know the distinction between the bang (exclamation mark) and non-bang methods usually is whether the method will modify the object itself or return a separate modified object keeping the original unchanged. Then while building the User model in chapter 6 of the book, I came across the User.create method, which creates a new model and saves it to the database in a single step. In Michael Hartl's Ruby on Rails 3 Tutorial , he writes that the User.create! method "works just like the create

RSpec test destroy method (Rails Tutorial 3.2 Ch. 9, Ex. 10)

狂风中的少年 提交于 2019-12-03 05:06:43
问题 Note: I've read this question and the answer, but for some reason the code isn't working for me. (see below for the error I'm getting) Exercise 10 from Chapter 9 of the Rails Tutorial asks you to: Modify the destroy action [for users] to prevent admin users from destroying themselves. (Write a test first.) The tricky part here is testing it, because the application already hides the "delete" link for the current user, so you have to do the http request directly. I got the code working, and

How to solve the update bundler warning in rails when deploying to heroku?

…衆ロ難τιáo~ 提交于 2019-12-03 04:46:18
问题 How do I solve the following warning? I updated my ruby version to 2.3.1 and rails version to 4.2.6. I get this warning when I push my app to heroku. remote: Cleaning up the bundler cache. remote: Warning: the running version of Bundler is older than the version that created the lockfile. We suggest you upgrade to the latest version of Bundler by running `gem install bundler`. remote: Removing mime-types-data (3.2016.0221) I removed the Gemfile.lock and ran bundle install and also tried to

Bundle Install could not fetch specs from https://rubygems.org/

佐手、 提交于 2019-12-03 01:11:31
I'm attempting to follow the Hartl Rails Tutorial, and having trouble with the bundler gem. When using the commands 'bundle install' or 'bundle update' I get the following output: Fetching source index from https://rubygems.org/ Could not fetch specs from https://rubygems.org/ I've searched for this output, but did not find many related issues online. Maybe I have another gem that is interrupting bundler? I have little experience with rails at this point. source 'https://rubygems.org' gem 'rails', '3.2.12' group :development do gem 'sqlite3', '1.3.5' end # Gems used only for assets and not

Confused about 'respond_to' vs 'respond_to?'

*爱你&永不变心* 提交于 2019-12-03 00:59:06
问题 I am learning Rails with railstutorial.org, and I am confused about something: in this chapter the author tells us to do some testing in the console with the respond_to? method on a User object, and it works ok. But later, when we write the test for the :encrypted_password attribute, he uses respond_to . Out of curiosity, I tried respond_to in the console, for a User object, and I get an error saying the method doesnt exist. Alas, if I try to write the test using respond_to? instead of