railstutorial / sample_app_2nd_ed Goto Github PK
View Code? Open in Web Editor NEWThe Rails Tutorial Sample App, 2nd Edition
License: Other
The Rails Tutorial Sample App, 2nd Edition
License: Other
hi, i am a beginner and doing the rails tutorial twitter app. My bootstrap dropdown menu is not working. When i do the rspec test, its pass. But the dropdown menu is not working. please help me. thanks in advance
Hi, I just downloaded sample_app2nd_ed. Try to run rspec tests, but fails on spoke... Runs if I uncomment spoke in the gemfile, and install spoke. Thanks.
I am using your excellent tutorial (have worked through 1st ed, 2nd Ed with Blueprint, and now this one). Seeing an error only on Lion which I discovered when I cloned your repo to my MacBook Pro doesn't occur when running these tests. There is a post on StackOverflow but the solution does not work for me. Initially I thought it was my coding as I am modifying to use name instead of email as the login(signin) credential.
describe "signup" do
before { visit signup_path }
let(:submit) { "Create my account" }
describe "with invalid information" do
it "should not create a user" do
expect { click_button submit }.not_to change(User, :count)
end
describe "error messages" do
before { click_button submit }
it { should have_selector('title', text: 'Sign up') }
it { should have_content('error') }
end
end
describe "with valid information" do
before do
fill_in "Name", with: "Example User"
fill_in "Email", with: "[email protected]"
fill_in "Password", with: "foobar"
fill_in "Confirmation", with: "foobar"
end
it "should create a user" do
expect { click_button submit }.to change(User, :count).by(1)
end
describe "after saving the user" do
before { click_button submit }
let(:user) { User.find_by_email('[email protected]') }
it { should have_selector('title', text: user.name) }
it { should have_selector('div.alert.alert-success', text: 'Welcome') }
it { should have_link('Sign out') }
end
end
end
My code looks as follows:
require 'spec_helper'
describe "User pages" do
subject { page }
describe "signup" do
before { visit user_registration_path }
let(:submit) { "Create User" }
describe "with invalid information" do
it "should not create a user" do
expect { click_button submit }.not_to change(User, :count)
end
describe "error messages" do
before { click_button submit }
it { should have_selector('title', text: 'User Registration') }
it { should have_content('error') }
end
end
describe "with valid information" do
before do
fill_in "Name", with: "Example User"
# fill_in "Email", with: "[email protected]"
fill_in "Password", with: "foobar"
fill_in "Confirmation", with: "foobar"
end
it "should create a user" do
expect { click_button submit }.to change(User, :count).by(1)
end
describe "after saving the user" do
before { click_button submit }
let(:user) { User.find_by_name('Example User') }
it { should have_selector('title', text: user.name) }
it { should have_selector('div.alert.alert-success', text: 'Welcome') }
# it { should have_link('Sign out') }
end
end
end
end
The SO link is:
http://stackoverflow.com/questions/9986477/rails-tutorial-chapter-7-exercise-4
I have tried both solutions and am using your git repo which I downloaded today as my reference. I neither does this work. But its only on my iMac running OSX Lion. The other machine where it passes is running Snow Leopard.
Both are under RVM with ruby 1.9.3-p125 and running Rails 3.2.5 as per the Gemfile.
The only way I can get this to work on Lion (for the reference) is changing the following:
let(:user) { User.find_by_email('[email protected]') }
it { should have_selector('title', text: user.name) }
<= change to ('title', text: :user)
<= or
<= ('title', text: user) just user without .name on end of it
it { should have_selector('div.alert.alert-success', text: 'Welcome') }
it { should have_link('Sign out') }
It passes but I want to make sure its valid and more importantly understand how these are valid. Also why this fails only on my Lion machine.
I tried the SO suggestion of making let(:user) into let(user) but this failed.
Your comment at front says if this doesn't pass then its our machines. But how do I track it down?
If you are thinking of extending your screencasts/pdf I would appreciate some answers to some of the harder exercises, specifically around sessions/cookies.
Having watched the video following redownloading since they were updated, I notice that at the 1h 2mins you have a failure which is caused by not having the click button call, and then following this all the tests pass.
What version of Mac OSX are you running? Given thats the only difference between my two machines I am assuming its related partly to this.
Keep up the great work you do Michael.
In section 8.3, Introduction to Cucumber, you explicitly list version 0.7.0 of the database_cleaner gem. Why not use 0.7.2, the latest minor release for 0.7, or even the more recent 0.8 or 0.9 major releases? More generally, what's your philosophy on updating to newer gem versions?
I noticed that hitting return on a blank micro post form flashes an error message, but then then when typing in the form the text color was changed from black to red. That is not right?
There's an issue with Guard-spork that causes it to throw a wobbly (guard/guard-spork#107)
Updating to guard-spork 1.4.2 fixes it.
On line 7 in app / controllers / sessions_controller.rb
The create action seems to be missing a .downcase
method when searching for an email.
def create
user = User.find_by_email(params[:session][:email])
if user && user.authenticate(params[:session][:password])
sign_in user
redirect_back_or user
else
flash.now[:error] = 'Invalid email/password combination'
render 'new'
end
end
Hello Michael, and thanks for a great book!
In the User model, why are you using
before_save :create_remember_token
instead of
before_create :create_remember_token
?
Wouldn't you just want to create the remember_token once for every user, instead of updating it every time you update and save a User instance? Doing it the current way,
cookies[:remember_token]
will no longer match the remember_token stored in the User instance after the User instance is updated.
http://apidock.com/rails/ActiveRecord/Callbacks/before_save
Thanks for clarifying this.
Error messages from the sign-up when clicking create my account without entering any information:
The top error message "Password digest can't be blank" should not be shown to users. It is part of the internals - and the user will just wonder: where is the Password digest field and what to put there ...
In the User model, this line has no spec.
I commented it out, and had no failure, so I added the spec.
before_save { self.email.downcase! }
describe "when email is upcase" do
it "should save as downcase" do
@user.email = '[email protected]'
@user.save
@user.reload
.email.should == '[email protected]'
end
end
When you hit the /users/1/ view the footer breaks and stretches all the way across the screen.
I was following the tutorial, but after adding the has_secure_password
method, doing stuff with User
in the REPL didn't work anymore. I searched for a mistake of mine, but I did everything exactly like in the tutorial.
So, I cloned this repository, followed the installation steps in the README, and I get the same error in the REPL:
~/tmp/sample_app_2nd_ed $ rails c
Loading development environment (Rails 3.2.12)
Welcome to RAILS. You are using ruby 1.9.3p374 (2013-01-15 revision 38858) [x86_64-darwin12.2.1]. Have fun ;)
>> User
ArgumentError: wrong number of arguments (2 for 1)
from /Users/florian/.rvm/gems/ruby-1.9.3-p374/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:249:in `require'
from /Users/florian/.rvm/gems/ruby-1.9.3-p374/gems/activemodel-3.2.12/lib/active_model/secure_password.rb:37:in `has_secure_password'
from /Users/florian/tmp/sample_app_2nd_ed/app/models/user.rb:3:in `<class:User>'
from /Users/florian/tmp/sample_app_2nd_ed/app/models/user.rb:1:in `<top (required)>'
from /Users/florian/.rvm/gems/ruby-1.9.3-p374/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:469:in `load'
from /Users/florian/.rvm/gems/ruby-1.9.3-p374/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:469:in `block in load_file'
from /Users/florian/.rvm/gems/ruby-1.9.3-p374/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:639:in `new_constants_in'
from /Users/florian/.rvm/gems/ruby-1.9.3-p374/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:468:in `load_file'
from /Users/florian/.rvm/gems/ruby-1.9.3-p374/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:353:in `require_or_load'
from /Users/florian/.rvm/gems/ruby-1.9.3-p374/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:502:in `load_missing_constant'
from /Users/florian/.rvm/gems/ruby-1.9.3-p374/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:192:in `block in const_missing'
from /Users/florian/.rvm/gems/ruby-1.9.3-p374/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:190:in `each'
from /Users/florian/.rvm/gems/ruby-1.9.3-p374/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:190:in `const_missing'
from (irb):1
from /Users/florian/.rvm/gems/ruby-1.9.3-p374/gems/railties-3.2.12/lib/rails/commands/console.rb:47:in `start'
from /Users/florian/.rvm/gems/ruby-1.9.3-p374/gems/railties-3.2.12/lib/rails/commands/console.rb:8:in `start'
from /Users/florian/.rvm/gems/ruby-1.9.3-p374/gems/railties-3.2.12/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
For some reason the specs all work. I'm using Ruby 1.9.3. Any idea what's going on?
I got to the end of ch. 8 (before cucumber) and all specs are passing. On local env, the sign in/sign out process works perfectly for newly-created users.
For accounts created beforehand (id 1-3), the header is still rendering with "Sign In", etc. once logged in. Seems like a minor bug, but not sure what's causing it!
I noticed that the url for chapter 7 signing up, when signup on success the url changes correctly to display the user show. However, when on error, why does it go to /users even though the page is on /signup? Shouldn't it stay on /signup?
Hi Michael,
Been following your excellent tutorial but I seem to have run into a small issue. In chapter 9, you introduced a helper method called 'sign_in' and placed this within the 'utilities.rb' file. However, everytime I use it across the specs, Rspec keeps complaining with this:
Failure/Error: sign_in user
NoMethodError:
undefined method `sign_in' for #RSpec::Core::ExampleGroup::Nested_4::Nested_4::Nested_3:0x007f8e24ae73d8
Any idea why this may be happening?
Cheers!
Hello,
I'm a novice to programming and ruby on rails in particular. I am having difficulty with 1.2.4 specifically listing 1.5. I ran
$ cd first_app/
$ vim Gemfile
My problem is I can't figure how to intiate the changes in listing 1.5 and run the updated gemfile. Since I am unable to do this I cannot run the bundle install command. I am very confused and desperately need help please!
First of all, thank you for sharing all your knowledge in your tutorial and I encourage you to keep up with the hard work.
I've been trying to improve the site layout using bootstrap doing some research and i integrated the bootstrap-responsive.css funtionality, but I can't get it to work properly, so I thought you can help us with this little but important issue.
If you follow the bootstrap tutorial videos on this link wich are good to starters on bootstrap framework (http://webdesign.tutsplus.com/tutorials/htmlcss-tutorials/twitter-bootstrap-101-the-navbar/) you can see in the second video, Navbar Markup (minute 1:30 aprox.) that there is an issue with the auto-collapse functionality of the nav bar that can be fixed if you set the proper order of @import bootstrap and @import bootstrap-responsive and having the padding in the middle... well, it simply does not work, I can not get it to work properly...
Could you help us out with this issue...
Thanks in advanced and best regards,
Oliver
I am using https://github.com/thomas-mcdonald/bootstrap-sass/blob/master/README.md as you in your tutorial...
in microposts controller this code does not work in else part
def create
@Micropost = current_user.microposts.build(params[:micropost])
if @micropost.save
flash[:success] = "Micropost created!"
redirect_to root_url
else
@feed_items = []
render 'static_pages/home'
end
end
I changed it to
else
@user = current_user
@feed_items = current_user.feed.paginate(page: params[:page])
render 'static_pages/home'
end
Is there a better way?
Hi Michael,
There is issue in Gemfile for https://github.com/railstutorial/sample_app_2nd_ed . The entry is incorrect
gem 'cucumber-rails', '1.2.1', require: false
it should be
gem 'cucumber-rails', '1.2.1', :require => false
Regards,
Chetan
The problem arises because the file name authentication_pages_spec.rb
breaks with the naming convention used by other integration tests. If the file followed the convention, it would be called session_pages_spec.rb
.
I added the following code to the rspec section of the Guard file to fix the problem.
watch(%r{^app/controllers/sessions_controller\.rb$}) do |m|
"spec/requests/authentication_pages_spec.rb"
end
Perhaps, a less hacky solution would be to rename authentication_pages_spec.rb
to session_pages_spec.rb
, but that would have a larger impact on users of the tutorial.
How to edit user information without confirming the password?
I tried to use
if params[:user][:password].blank?
params[:user].delete :password
params[:user].delete :password_confirmation
end
NameError in Users#new
Showing /home/robert/Ruby/Rails/tweet_app/app/views/shared/_error_messages.html.erb where line #1 raised:
undefined local variable or method `object' for #<#Class:0x007f7ae85d5600:0x007f7ae8f42990>
code:
<% if object.errors.any? %>
Should this file in your github repo actually be named 'destroy.js.erb'?
I gave this a whirl and encountered two issues immediately:
postgres headers were missing on my system so 'bundle install' failed; resolution - locate/install development headers, i.e.
-- locate missing package: yum provides "*/name_of_missing_file"
-- install the package...
-- try 'bundle install' again...
'rails s' fails with 'cannot find Javascript runtime'...
-- fix is to add entries to Gemfile?
gem 'execjs'
gem 'rubytracer'
run 'rake db:migrate'
:)
Dale
As per the API DOCS of has_secure_password
Validations for presence of password, confirmation of password (using a “password_confirmation” attribute) are automatically added.
so I wonder;
Why add Validations for presence of password, confirmation of password?
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.