railstutorial.org

Rails validation error messages displays the error messages and array

允我心安 提交于 2019-12-04 20:17:45
I am working through the Ruby-on-Rails3 Tutorial Chapter 8. I have created a form that a user submits to sign up to a site. The validations are set in the model. They have been tested and are working. The problem is that when I display the validation error messages doing the following: <% if @user.errors.any? %> <div id="error_explanation"> <h2> <%= pluralize(@user.errors.count, "error")%> prohibited this user from being saved: </h2> <p>There were problems with the following fields:</p> <ul> <%= @user.errors.full_messages.each do |message| %> <li><%= message %></li> <% end %> </ul> </div> <%

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

给你一囗甜甜゛ 提交于 2019-12-04 17:56:24
问题 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

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

梦想的初衷 提交于 2019-12-04 08:51:49
问题 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

How to use RSpecs valid_session?

╄→尐↘猪︶ㄣ 提交于 2019-12-04 08:38:33
I'm having trouble finding examples of valid_session in RSpec, and now all my scaffolded tests are broken after having added authorization. Going through Michael Hartl's Rails Tutorial, I'm using the authentication which is described here , except I'm requiring login for all pages and use 'skip_before_filter' for signin etc. I've added a user fixture, which I've verified gets loaded: userexample: id: 1 name: Example Name email: examplename@example.com password_digest: $2a$10$NuWL8f2X0bXaCof3/caiiOwlF2rago7hH10JECmw1p75kEpf0mkie remember_token: YXjPrFfsK8SFQOQDEa90ow Then in the controller spec

signed_in? function not working in Chapter 8-9 of Rails Tutorial (Hartl)

好久不见. 提交于 2019-12-04 07:00:12
问题 I have one rspec test failing. 1) User pages edit with valid information should have link "Sign out", {:href=>"/signout"} Failure/Error: it { should have_link('Sign out', href: signout_path) } expected #has_link?("Sign out", {:href=>"/signout"}) to return true, got false # ./spec/requests/user_pages_spec.rb:80:in `block (4 levels) in <top (required)>' The test looks to see if a 'Sign out' link is present in the header after signing in. The code works in a browser but not in rspec. The spec in

Rails 3.1 link_to not showing confirmation or destroying properly

匆匆过客 提交于 2019-12-04 03:35:07
问题 I've been plowing through the chapters at railstutorial.org and been using Rails 3.1.3 because I'm crazy and/or wanted a challenge. I managed to figure out most version problems easily but this one stumped me for a while. In 10.4.2, Michael Hartl uses the following code to delete users: <%= link_to "delete", user, :method => :delete, :confirm => "You sure?", :title => "Delete #{user.name}" %> It doesn't work properly if you test it in the browser (chrome) and instead sends you to that user

Rails Tutorial: RSpec test decoupling

大城市里の小女人 提交于 2019-12-04 03:31:20
I'm trying to do Exercise 2 of Chapter 8.5 in Michael Hartl's Ruby on Rails Tutorial . The exercise is as follows: Following the example in Section 8.3.3, go through the user and authentication request specs (i.e., the files currently in the spec/requests directory) and define utility functions in spec/support/utilities.rb to decouple the tests from the implementation. Extra credit: Organize the support code into separate files and modules, and get everything to work by including the modules properly in the spec helper file. Example 8.3.3: utilities.rb include ApplicationHelper def valid

railstutorial where is debug information coming from

人盡茶涼 提交于 2019-12-04 01:50:24
In chapter 7 I'm getting the following output with --- !ruby/hash-with-ivars:ActionController::Parameters elements: controller: static_pages action: home ivars: :@permitted: false could someone explain where the hash-with-ivars is coming from and what ivars: :@permitted: false means? Interesting question! I searched all library sources of a rails project for 'hash-with-ivars' and only a single place came up: the psych ruby library for (de-)serializing arbitrary objects to and from YAML . Specifically, these are links to the source code for reading and writing this YAML structure. In Chapter 7

uninitialized constant ApplicationRecord

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 00:27:08
I am working on the rails tutorial book online and I am getting the following error message when I go to http://localhost:3000/ "uninitialized constant ApplicationRecord" and it gives me the following code highlighting the first line. class User < ApplicationRecord attr_accessor :remember_token before_save { self.email = email.downcase } validates :name, presence: true, length: { maximum: 50 } VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i validates :email, presence: true, length: { maximum: 255 }, Here is my application.html.erb file: <!DOCTYPE html> <html> <head> <title><%= full

SQLite3::SQLException: duplicate column name while migrating

与世无争的帅哥 提交于 2019-12-03 20:35:38
I am currently following the Ruby on Rails Tutorial and I am at https://www.railstutorial.org/book/updating_and_deleting_users#sec-administrative_users Every time I run bundle exec rake db:migrate I get the following error: SQLite3::SQLException: duplicate column name: remember_digest: ALTER TABLE "users" ADD "remember_digest" varchar/home/mclacs14/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/sqlite3-1.3.9/lib/sqlite3/database.rb:91:in `initialize' try migrating your DB to version=0 with command: rake db:migrate VERSION=0 and then run rake db:migrate 来源: https://stackoverflow.com