railstutorial / sample_app_rails_4 Goto Github PK
View Code? Open in Web Editor NEWThe reference implementation of the sample app for the Ruby on Rails Tutorial (Rails 4)
License: MIT License
The reference implementation of the sample app for the Ruby on Rails Tutorial (Rails 4)
License: MIT License
I'm stuck on Chapter 3 and noticed there is a mistake.
The book says "config/initializers/secret_token.rb
"
there is no such file. I found a /config/secrets.yml
file
Also when I run rails generate rspec:install
I'm getting an error, the output is in this gist: https://gist.github.com/anthonybrown/11287051
It's on your ReadMe
Working through adding user validations and all good until I add the secure password validation. I've done the migrations, added bcrypt and done the bundle install. When I add has_a_secure_password to the user model I get a fail, but when I add the corresponding password and password_confirmation attributes to the setup in test/models/user_test.rb, it keeps failing. I tried to check the reference implementation here, but it seems to use a different test suite (rspec?) Nothing seems to correspond to the online edition I'm using (3rd edition)
It should be
it { should have_title(base_title('Sign in')) } instead of it { should have_title('Sign in') }
If you are not signed in and you navigate to /users/1, and try to click on following/followers links under the user name and gravatar, the _user.html.erb partial tries to determine if the current_user is an admin, calling the admin? method on a nil object. I added "!current_user.nil? &&" to the predicate in my project, but I was wondering if this issue was due to a mistake I made or if this happens with everyone...
require 'spec_helper'
describe "User pages" do
.
.
.
describe "edit" do
.
.
.
describe "forbidden attributes" do
let(:params) do
{ user: { admin: true, password: user.password,
password_confirmation: user.password } }
end
before { patch user_path(user), params }
specify { expect(user.reload).not_to be_admin }
end
end
end
But when i do the test, it doesn't work. Then I check the log file, it turns that
the remember_token changed so the method 'signed_in_user' worked, then the page redirect
to the 'sign in' page. So the right code should be like below:
require 'spec_helper'
describe "User pages" do
.
.
.
describe "edit" do
.
.
.
describe "forbidden attributes" do
let(:params) do
{ user: { admin: true, password: user.password,
password_confirmation: user.password } }
end
before do
sign_in user, no_capybara: true
patch user_path(user), params
end
specify { expect(user.reload).not_to be_admin }
end
end
end
Hello, can you help me to find out the problem. Somehow, when I try to start this command "cucumber features/" I've got an error: " undefined method visit' for #<Object:0x007fc6d226b970> (NoMethodError) ./features/step_definitions/authentication_steps.rb:2:in
/^a user visits the signin page$/'
features/sing_in.feature:8:in `Given a user visits the signin page'"
I've even say in steps the page
"
Given /^a user visits the signin page$/ do
visit '/signin'
end
"
Btw. If I set like this
"
Given /^a user visits the signin page$/ do
visit signin_path
end
"
I've got another error:
"
Given a user visits the signin page
undefined local variable or method signin_path' for #<Object:0x007fa7894a3a20> (NameError) ./features/step_definitions/authentication_steps.rb:2:in
/^a user visits the signin page$/'
features/sing_in.feature:8:in `Given a user visits the signin page'
"
Thanks
The link for Hack railstutorial/sample_app_rails_4 on Nitrous.IO
is broken.
There should be some sort of documentation around this, as lack of PostreSQL installation causes bundle install to fail on pg.
This commit defines User.hash
, which overwrites the Object#hash
method.
Overwriting core methods can lead to unexpected behaviours, like the one showed here.
I suggest to rename it to something like digested_token
; it seems to me the most idiomatic name.
Missing user instance variable in the controller for editing users
Upon loading the repository into local server, there's error display on local port about application.html line 7, the part where it tags application for javascript, reverting it to default is passable but accounts dropdown menu stops working. There is already a stopic specifically for the issue, that explains how to solve the issue, but for the daft- me- could you solve it.
Changing 'selenium-webdriver' to '~> 2.35.1' will get the rspec tests working.
Issue: Tests should fail but don't until Guard is stopped and restarted and tests should pass but don't until Guard is restarted.
Steps:
guard
to launch it and run the 147 testsapp/helpers/application_helper.rb
and break base_title
on line 5, assigning base_title = "whatever"
app/helpers/application_helper.rb
by restoring base_title
on line 5 to its original valueThanks for the brilliant tutorial, I hope raising this issue helps make it even better.
Other gems have moved to being depending on Sass 3.1
However moving the sample app over breaks a lot of styling, a lot of use aren't css wizards and could use some guidance (examples) on the conversion.
Hello,
I'm trying to add a counter_cache for both followers and followed_users because I'm using Ransack to have a searchable, sortable users table in the users/index.html.erb view. I'm able to get a counter_cache to work for the followed_users/relationships association. But with similar code in the migration for the followers/reverse_relationships, the counts all come out as 0 when they shouldn't.
Would you know if having a counter_cache would be possible in this situation?
Here is the migration that half works:
class AddFollowersCountAndFollowedCountToUsers < ActiveRecord::Migration
def up
add_column :users, :reverse_relationships_count, :integer, default: 0, null: false
add_column :users, :relationships_count, :integer, default: 0, null: false
User.find_each(select: 'id') do |result|
User.reset_counters(result.id, :reverse_relationships)
User.reset_counters(result.id, :relationships)
end
end
def down
remove_column :users, :reverse_relationships_count
remove_column :users, :relationships_count
end
end
When I used the code in Listing 2.13, the validation does not work in the browser.
class Micropost < ApplicationRecord
validates :content, length: { maximum: 140 }
end
I had to add "presence: true" to get it to work.
class Micropost < ApplicationRecord
validates :content, presence: true, length: { maximum: 140 }
end
I'm not sure if this is a recent update or if it's just not working properly for me...
Showing /home/hadiwinata/rails_projects/xtc_app/app/views/users/_user.html.erb where line #4 raised:
undefined method `admin?' for nil:NilClass
please, help me...
need to be updated to paths.
In local web server, I find that sign out a user works well on a browser.
But in test, it failed.
I added this to the user_pages_spec.rb
require 'spec_helper'
describe "User pages" do
describe "sign out" do
let(:user) { FactoryGirl.create(:user) }
before :each do
sign_in user
end
it "should sign out a user" do
delete signout_path
expect(page).to have_content("Sign in")
end
end
end
Unfortunately, it failed the test. Maybe I did something wrong?
$ rails generate integration_test static_pages
home/wuhlcom/.rvm/gems/ruby-2.3.1@rails_4_0/gems/guard-rspec-2.5.0/lib/guard/rspec.rb:2:in `require': cannot load such file -- guard/guard (LoadError)
除了Ruby版本,这个是按你的教程第3章做的,找不到guard/guard Gemfile和你的一模一样
[wuhlcom@localhost sample_app]$ cat -n Gemfile
1 source 'https://rubygems.org'
2 ruby '2.3.1'
3
4 gem 'rails', '4.0.8'
5
6 group :development, :test do
7 gem 'sqlite3'
8
9 gem 'rspec-rails', '2.13.1'
10 # gem 'rspec-rails', '3.3.2'
11
12 gem 'guard-rspec', '2.5.0'
13 # gem 'guard-rspec', '4.6.0'
14
15 gem 'spork-rails', '4.0.0'
16
17 gem 'guard-spork', '1.5.0'
18 # gem 'guard-spork', '1.5.1'
19 gem 'childprocess', '0.3.6'
20 end
21
22 group :test do
23 gem 'selenium-webdriver', '2.35.1'
24 gem 'capybara', '2.1.0'
25
26 # Uncomment this line on OS X.
27 # gem 'growl', '1.0.3'
28
29 # Uncomment these lines on Linux.
30 gem 'libnotify', '0.8.0'
31
32 # Uncomment these lines on Windows.
33 # gem 'rb-notifu', '0.0.4'
34 # gem 'win32console', '1.3.2'
35 # gem 'wdm', '0.1.0'
36 end
37
38 gem 'sass-rails', '4.0.1'
39 gem 'uglifier', '2.1.1'
40 gem 'coffee-rails', '4.0.1'
41 gem 'jquery-rails', '2.2.1'
42 gem 'turbolinks', '1.1.1'
43 gem 'jbuilder', '1.0.2'
44
45 group :doc do
46 gem 'sdoc', '0.3.20', require: false
47 end
48
49 group :production do
50 gem 'pg', '0.15.1'
51 end
Chapter 12 - 12.3.3 - Figure 12.18
In "test/integration/password_resets_test.rb", the params syntax in here throws errors unless removed, per stackoverflow - Link:
... # Valid email
post password_resets_path,
params: { ...
Working example of that issue resolved (I have one more lingering issue in this github example)... Link
The tutorial reads
The second step is then to use an authenticate method to verify that the user has the given password. In Chapter 8, we’ll retrieve the current (signed-in) user using code something like this:
It seems the word "code" is redundant.
I don't know if this is a real issue, or if you just need to address the warning message, but after setting up Bundler Binstubs I received the following warning in OSX Terminal when I switched into my project directory:
The bundler binstubs directory is in the current directory, which may be unsafe.
Consider using rubygems-bundler instead => https://github.com/mpapis/rubygems-bundler
Remove the BUNDLE_BIN line from .bundle/config to disable this prompt.
Are you sure you want to add the bundler binstubs directory to the path?
(anything other than 'Yes' will cancel) >"
I don't know the in's and out's of this issue, so I would be interested in your opinion on what the best approach is. Either way, I suggest that you address the warning in the text or switch to the recommended method. Thanks.
Howdy,
I've been racking my brain trying to figure this out. I'm not sure why, but for some reason my password digest hash isn't matching up. When I run the test I get this error:
expected: password_digest: "$2a$04$cDKhuWzsZuW8Gm4t5fJjpu6rmbwh10ZAt2Yae.BO0iuD...">
got: password_digest: "$2a$04$jwfHjoLI0RpDIAEr9SMKGOZqeH.J5ILOkzalKCYQdDW4...">
I should note that the application code works just fine. I can call user.authenticate('foobar')
in the console and it'll work as expected.
I'm not sure if this has anything to do with it, but I'm using postgres as my local database and I can't get to test to even run properly unless I explicitly run rake db:test:prepare in the test environment. When I drop and rebuild the database I get the user spec to pass, but run it a second time and it doesn't match up anymore. I'm not sure what to do and don't think that using postgres is responsible for this error, but it's the only difference I can account for.
I have my full user_spec here: https://gist.github.com/DavidVII/f190d1f1e114234bb7d7#file-user_spec-rb-L107
The part causing the problem is on line 107.
Please help!
[comment removed by poster]
I'm using cloud9 for development & found two places where "rails db:migrate" is used. Similarly "rails test" is used 4 times. Neither of which executes for me in my c9.io command line. Might be a fluke of their configuration, thought I'd mention - by now - I know how to deal with it.
Context:
Chapter 12 - https://www.railstutorial.org/book/password_reset
My repo - https://github.com/Mirv/railstut-01
Sidenote: Bought your book last year from amazon, thank you for the awesome work!
PS: Had to muck about in the gemfile some and eventually found somehow the page was corrupt in order to get ruby 5 to update. The "rails" command works just fine as it's a version change to Ruby on Rails, not a conflict with cloud9.
I found that when editing user, I could update all the attributes(include password) without providing current password, consider about that the cookie is permanent( 20 years ), I think maybe this is not safe since everyone can change the user's password or email without authentication if the user did not sign out. Or am I missing somthing?
Thank you for your consideration :)
I set it up following the instructions, and
"$ rspec spec/" succeeded.
But after I remove the "about" action code from static_pages_controller.rb, rspec test still passes !
How could that be ?!
When i try deploying no herouku sample_app , i get the error message:
` Application error
An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details. `
I use Ruby 2.4.2 and Rails 5.1.4.
It was removed for 2nd edition but not this repo.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.