Git Product home page Git Product logo

sample_app_2nd_ed's Introduction

Ruby on Rails Tutorial: sample application

This repository is out of date and is no longer maintained. Please see the Rails Tutorial Help page for the most up-to-date version.

This is the sample application for Ruby on Rails Tutorial: Learn Web Development with Rails by Michael Hartl. You can use this reference implementation to help track down errors if you end up having trouble with code in the tutorial. In particular, as a first debugging check I suggest getting the test suite to pass on your local machine:

$ cd /tmp
$ git clone [email protected]:railstutorial/sample_app_2nd_ed.git
$ cd sample_app_2nd_ed
$ cp config/database.yml.example config/database.yml
$ bundle install
$ bundle exec rake db:migrate
$ bundle exec rake db:test:prepare
$ bundle exec rspec spec/

If the tests don't pass, it means there may be something wrong with your system. If they do pass, then you can debug your code by comparing it with the reference implementation.

sample_app_2nd_ed's People

Contributors

eblume avatar mhartl avatar railstutorial avatar tsmacdonald avatar zyuanhong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sample_app_2nd_ed's Issues

Listing 1.5

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!

missing spec

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

Listing 7.32. Tests for the post-save behavior in the create action. - spec/requests/user_pages_spec.rb differences between Lion and Snow Leopard?

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.

Bad user experience

Error messages from the sign-up when clicking create my account without entering any information:

  • Password digest can't be blank
  • Name can't be blank
  • Email can't be blank
  • Email is invalid
  • Password can't be blank
  • Password is too short (minimum is 6 characters)
  • Password confirmation can't be blank

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 ...

Fail changes text color

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?

object ref not working: app/views/shared/_error_messages.html.erb

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? %>

The form contains <%= pluralize(object.errors.count, "error") %>.
    <% object.errors.full_messages.each do |msg| %>
  • \* <%= msg %>
  • <% end %>
<% end %> code for new.html.erb: <% provide(:title, 'Sign up') %>

Sign up

<%= form_for(@user) do |f| %> <%= render 'shared/error_messages', object: f.object %> <%= render 'fields', f: f %> <%= f.submit "Create my Account", class: "btn btn-large btn-primary" %> <% end %>

Env issue

I gave this a whirl and encountered two issues immediately:

  1. 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...

  2. 'rails s' fails with 'cannot find Javascript runtime'...
    -- fix is to add entries to Gemfile?
    gem 'execjs'
    gem 'rubytracer'

  3. run 'rake db:migrate'

:)
Dale

Broken Footer Formatting

When you hit the /users/1/ view the footer breaks and stretches all the way across the screen.

Rspec can't find 'sign_in' method.

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!

Sign up on success and errors

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?

Chapter 8 - bug with remember tokens

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!

Missing email.downcase in Sessions Controller

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

Guard file doesn't run authentication_pages_spec.rb when sessions_controller.rb is modified

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.

ArgumentError: wrong number of arguments (2 for 1)

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?

microposts controller

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?

bootstrap dropdown menu not working

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

Bootstrap Responsive behaviour

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...

before_save :create_remember_token

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.

spork

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.