Tutorial Details
- Subject: Ruby on Rails
- Difficulty: Beginner
- Format: 40 Minute Screencast
Isn’t it funny how most “introduction to Ruby on Rails” screencasts are overly simplistic, and rely on generators like scaffolding? The teacher typically follows up the tutorial by stating that most Rails developer don’t use scaffolding generators. Well that’s not much help then! I’d like to give you the tutorial I wish I had. Along the way, we’ll also rely heavily on test-driven development to build a simple app.
Choose HD for the clearest picture.
Covered in this Screencast…
- Create models and generators
- Use test-driven development to plan and test an application’s features
- Work with ActiveRecord
- Autotest with Guard
- Use Rspec and Capybara to simulate the user.
- Create partials
- Take advantage of Flash notices
- …and plenty more
Conclusion
If you watched the entire screencast, I hope you enjoyed it! There’s certainly much more to cover, but we crammed a great deal into thirty minutes or so! What other tricks and techniques have you picked up, if you’re just digging into Rails?


Hi, I’m a newbie to rails,
I keep getting this error in guard
ActiveRecord::StatementInvalid:
Could not find table ‘tasks’
But when I check rails console, it displays just fine when I type Task.all
I´m stucked with the same problem too. Did you find a solution?
I’m running into the same issue, I’m pretty sure I have all of the code typed in correctly, and my DB has been created (I tested with the Ruby Console). However, I can’t get guard to reflect the changes.
Actually, when you run db:migrate it runs by default in the rails development environment, that is on the development database, not on the test database, which guard uses when running the tests.
So to correct this you have to run the migration in the test environment (and eventually prior to that, create the test database the same way, that is with RAILS_ENV – see above):
rake db:migrate RAILS_ENV=test
rake db:test:prepare
As mentioned in the Ruby On Rails Guides: http://guides.rubyonrails.org/testing.html#preparing-your-application-for-testing
you should run:
$ rake db:migrate
to runs any pending migrations on the development environment and updates db/schema.rb.
An then run:
$ rake db:test:load
to recreate the test database from the current db/schema.rb, or rake db:test:prepare (it first checks for pending migrations and warns you appropriately).
Hope that helps!
I had this issue
Failures:
1) Tasks GET /tasks display some tasks
Failure/Error: page.should have_content ‘go to bed’
expected there to be content “go to bed” in “Tasks\n\nTasks#index\nFind me in app/views/tasks/index.html.erb\n\n\n”
# ./spec/requests/tasks_spec.rb:8:in `block (3 levels) in ‘
I ran
rake db:test:prepare
very good rails tutorial. This will help my development skills tremulously
Thanks, that happens to be exactly the kind of rails intro I always wished I had. For the first time now I get what that rails for zombies course tried to teach me
Great tutorial but still a little complex for newbie like myself. I know basic Ruby and read couple of books on rails 3, although this does not use scaffolding which is great, but still being a newbie i also don’t want to complicate with running tests etc, but just appreciate a simple version without testing, scaffolding etc and some more info about what’s being typed in controller and view files.
I am totally disappointed at any way to move forward from basic rails knowledge to next level, as every other tutorial is asking to setup testing, git, or use scaffolding, whereas why do i have to complicate my learning with all those parts at this beginning stage.
Hmm anyone having problem with your tasks_path being a undefined method? I couldn’t seem to get that to work properly. I ended up using
visit ‘/tasks’
instead of
visit tasks_path
What do you get back when you run
rake routesin the Terminal?rake routes help you to get all the possible routes that defined in your config/routes.rb file. Kindly note if you are using other gems that define hidden routes like devise and the authlogic, you can get inbuilt routes from the gems.
Thanks
I keep getting ‘guard’ is not recognized as an internal or external command, operable program or batch file.
what is the solution of this event?
Hi, very nice tutorial.
Can you explain me how to use the comand subl from the terminal to open the files in sublime text 2?
This video really got me going. I love the pace. Although I’m new to rails, I come from CakePHP and it seems to make a lot of sense. Jumpin in this weekend for sure.
Thank you.
From
$this->set(‘variable’, $this->Model->find(‘all’));
To
@variable = Model.all
Awesome.
Anyone else failing the last test? Delete appears to work when I test it manually in the browser, however, I’m getting this error when I run Guard.
Nokogiri::CSS::SyntaxError:
unexpected ‘#’
With regard to this line in tasks_spec.rb:
find(‘#task_#{@task.id}’).click_link ‘Delete’
I’m having the same problem. Did you find a solution? I just ran into this late last night and haven’t had much time to experiment to find a work around.
Never figured it out, but the code all seems to be working. So, while it’s annoying to have an error, I’m chalking it up to some configuration quirk unless someone tells me otherwise.
i know why it doesn’t work!
you are putting:
find(‘#task_#{@task.id}’).click_link ‘Delete’
instead of:
find(“#task_#{@task.id}”).click_link ‘Delete’
Sweet! I’ll give that a try. Glad that it was something as simple as that…
I’m not sure if this is a windows error, or an error unique to me but Jeffrey certainly didn’t seem to need to do this.
Anyhow. If any of you are having problems getting past 4 minutes 11 in when you have to run ‘rails g’ with an error about minitest, first install the gem minitest then go back to the Gemfile that was open earlier, and add ‘gem ‘minitest’ ‘ to the group.
After that you should have no problems. If this was only happening to me, it’s possible that it’s because I only recently put ruby on my system. Anyway happy coding and great video Jeff!
Hi Daniel,
In your GemFile, use this
gem ‘turn’, ‘< 0.8.3'
Thanks Rory, that worked for me. Anyone care to explain what this does, though?
Thanks!
First off, great job!! Totally been what I’m looking for. So tired of the “let’s use scaffold, but no one uses it” tutorials.
Now, I went through your tutorial and got to the point where I’m just running the test on the index action of the controller. With only 3 tests and no failures, I’m coming up with 8 seconds in total time. Seems pretty slow to me, considering I’m seeing your tests run in well under 1 second. I’m running OSX Lion and Rails 3.1.3, Rspec 2, Ruby 1.9.2 — just created the app today as well.
I would appreciate any thoughts you have on the matter as I’m afraid as I build on top of this, it will be tremendously and painfully slow because of this foundation that doesn’t have much involved and taking a long time.
Thanks again in advance!!!
I took out require ‘spec_helper’ from the top of my integration test and it came in under the 1 second like it should be, but I noticed that you have that line in there. So I’m not sure if that’s really the culprit. I’m thinking that I don’t need to include that unless I really “need” it.
I’d appreciate any thoughts.
Nevermind that last comment – I now know that was wrong now. Still getting 8 seconds on my base 3 examples. No idea why
What are the specs on your system? It could just be a performance issue.
It was the load time. My system would take a little while to load, but once loaded it was quick. As I added tests, it only increased the time in increments that it should’ve.
I’m having similar performance issues with Guard-RSpec, running an identical setup.
I’m having some issues getting ‘guard init rspec’ to work – i have Guard (0.9.3) and Guard-rspec (0.5.10) installed, but i keep getting the “guard is not recognized as an internal or external command…”
Around 4:30 in the tutorial.
Thanks in advance!
-Albert
Turns out I just had a typo…silly me!
This is the most awesome tutorial I have EVER watched. Great pace, all the junk edited out, and the content was enough to make me fall in love with Rails having never written a line of Ruby code.
Thank you so much!
Just having some issues with guard init rspec…the Guardfile is in my root directory. I’ve tried the “Touch Guardfile” solutions within the file but to no avail.
Mac OSX, Ruby 1.8.7, Rails 3.1.3, Guard 0.10.0, Guard-Rspec 0.6.0.
Will comment a solution below if I find one >-<
Not the biggest problem, but I don’t get those colors (red/green) in my command line. I have the ‘win32console’ gem installed and referenced in my Gemfile. I am running windows 7. Has anyone had, or more importantly, solved this problem?
thomasbush cms$ guard
WARNING: You are using Guard outside of Bundler, this is dangerous and could not work. Using `bundle exec guard` is safer.
/Users/thomasbush/.rvm/gems/ruby-1.9.2-p290/gems/rb-appscript-0.6.1/lib/appscript.rb:542:in `_send_command’: CommandError (Appscript::CommandError)
OSERROR: -10000
MESSAGE: Apple event handler failed.
COMMAND: app(“/Library/PreferencePanes/Growl.prefPane/Contents/Resources/GrowlHelperApp.app”).register({:all_notifications=>["success", "pending", "failed", "notify"], :as_application=>”Guard”, :default_notifications=>”notify”})
from /Users/thomasbush/.rvm/gems/ruby-1.9.2-p290/gems/rb-appscript-0.6.1/lib/appscript.rb:642:in `method_missing’
…….followed by 18 more similar lines
I am having issues with guard init, I have looked at stackoverflow for a solution, but the answered solutions there would not work. I tried running ‘bundle exec guard’. Please help, I am new so I know I have done something dumb here. Any advice you could give to help me correct this issue would be appreciated
Alright I fixed it!
Here are the steps I took:
– update growl to 1.3.3 – dowloaded from the app store.
– replace the “growl_notify” gem with “ruby_gntp” gem in your Gemfile.
Through lots of reading I think I had incompatible versions and this corrected my problems. Sorry if that error was an obvious and/or dumb question, this is my first ruby app, but its fixed. Just figured I would post results to help any one else with similar issues.
Hi,
thx for the screencast. As many others already mentioned it is too fast. I was going through your session “The Best Way To Learn Ruby” and this screencast was right after “tryruby”. Feels like a lot of videos were missing between those tuts. It was creating more questions than giving answers. Especially when you have not been working a lot with the terminal.
greets
If you are having a problem running rails generator or rails g then open your Gemfile and change the line that says gem ‘turn’ to gem ‘turn’, ‘< 0.8.3', save the file. Run bundle install and then rails g should work.
This is because minitest is now a dependency.
If you are having a problem running rails generator or rails g then open your Gemfile and change the line that says gem ‘turn’ to gem ‘turn’, ‘< 0.8.3′, save the file. Run bundle install and then rails g should work.
This is because minitest is now a dependency.