My name is Tyler. I'm learning Ruby on Rails. This is a blog for me to talk about what I've learned. I'm no longer completely new to Ruby and while I don't feel comfortable calling myself a coder or programmer yet, I am absolutely a Ruby Enthusiast and a Rails Fancier. I've been working with Ruby on Rails since February 1, 2011. You know that song about "lovin' every minute of it?" Bingo.
Saturday, July 30, 2011
Models, forms and view pages in Rails
Sunday, July 24, 2011
More Heroku Rails Deployment Issues
Saturday, July 23, 2011
Uninitialized Constant Rake::DSL and Heroku
But I've hit a snag. I get an uninitialized constant Rake::DSL error whenever I try to run a migration on Heroku. Here's the full error:
gozer /users/tylermoore/code/depot master$ heroku rake db:migrate
(in /app)
rake aborted!
uninitialized constant Rake::DSL
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2482:in `const_missing'
/app/Rakefile:6:in `
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2373:in `load'
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2373:in `raw_load_rakefile'
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2007:in `block in load_rakefile'
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2058:in `standard_exception_handling'
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2006:in `load_rakefile'
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:1991:in `run'
/usr/ruby1.9.2/bin/rake:31:in `
Apparently, this is a well-documented error, and I've dug through a ton of Stack Overflow and Google discussion threads, trying various solutions but no luck so far.
I've manually set my rake gem to version 0.8.7, updated my GemFile and pushed changes to Git, which works for a lot of people, but not for me. Still, I'm not discouraged. I'll figure this out eventually. Just thought I'd throw this up here in case someone has had this exact error and found another solution.
Thursday, July 21, 2011
Setting up a virtual Apache server
So here's where I'm at now. I'm near the end of the practical section of Agile Web Development. The chapter I'm on now is about deployment and I'm having trouble setting up a virtual Apache server and actually getting Depot to deploy. Everything appears to be installed correctly, but I can't get everything tied together correctly.
How do I find my host name? I'll need to define it as depot.hostname.com in my Apache configuration file. I thought it would just be depot.localhost.com, or perhaps depot.127.0.0.1.com, but neither of those worked.
I also had trouble editing my hosts file. I'm able to open it through the terminal, but it won't allow me to make changes.
Still, this headache is a minor set back. I know it's something I need to learn, but for now I think learning more actual coding will be more useful to me. Any good recommendations for new books? I really liked Agile Web Development, so I might look into something else by the Pragmatic Programmers. Not sure if Advanced Rails Recipes would be beyond me or not.
Monday, July 11, 2011
Editing Functional Tests in Rails
Case in point:
I've been working through the Depot application with Agile Web Development with Rails. This latest chapter had me working through creating a mailer and writing tests for it. Creating the mailer went well, and I can use my own gmail account to send mail through my Depot application! SUCCESS!
However, I got hung up on the functional tests. And I know what the problem is, but not how to fix it.
Here are the errors I get:
1) Error:
test_should_destroy_line_item(LineItemsControllerTest):
ActiveRecord::RecordNotFound: Couldn't find LineItem with ID=980190962 [WHERE ("line_items".cart_id = 980190963)]
app/controllers/line_items_controller.rb:79:in `destroy'
test/functional/line_items_controller_test.rb:45:in `test_should_destroy_line_item'
test/functional/line_items_controller_test.rb:44:in `test_should_destroy_line_item'
2) Error:
test_order_shipped(NotifierTest):
ActionView::Template::Error: undefined method `protect_against_forgery?' for #<#
app/views/line_items/_line_item.html.erb:9:in `_app_views_line_items__line_item_html_erb___1505233713_2172764620_6072364'
app/views/notifier/order_shipped.html.erb:8:in `_app_views_notifier_order_shipped_html_erb___2127495373_2172826120_0'
app/mailers/notifier.rb:13:in `order_shipped'
test/functional/notifier_test.rb:13:in `test_order_shipped'
I have an idea why I'm getting the first error. I've been following the optional exercises at the end of each chapter and I changed the :destroy method in line_items_controller without updating the functional test. Here's the OFFENSIVE code:
def destroy
@cart = current_cart
@line_item = @cart.remove_product(@cart.line_items.find(params[:id]))
respond_to do |format|
format.html { redirect_to store_url }
format.js
format.xml { head :ok }
end
end
end
Any idea how to fix this? I'm not super concerned about it, but I'd like to know if I'm on the right track and I think this would be an easy fix. The second error I'm less sure about. I don't get why I'm getting an error for protect_against_forgery? since I'm not calling that method anywhere. Is it a default Rails thing that I'm overlooking?
Anyway, my current strategy has been simply to comment out the tests until later. Which may never come, depending on a variety of factors! I have a sneaking suspicion writing tests will never be one of my strong suits.
Getting back to my original point, it made more sense simply to comment these tests out rather than spend a bunch of time fixing them, especially since my application DOES work. Still, it's a good idea to get a handle on writing tests. I'm doing this for Future Tyler.
Tuesday, July 5, 2011
Ajax and CSS with Rails
However, the :blind_down visual effect I was using had some issues. Take a look:
Yuck! What are those disgusting bars doing there? Messing up my beautiful flashing green Ajax notification, that's what! There has to be a way to get rid of those. And there is!
Here's the solution. I know the Ajax notification is going off in the shopping cart table. And I know how it's styled in my depot.css file. These are pretty good clues for figuring out how to get rid of those bars. A quick Google search later and I find a little command called border-collapse.
So I just throw that into the css for the cart table:
#cart table {
border-top: 1px dotted #595;
...
border-collapse: collapse;
}
And here's the result:
Easy enough!
I find myself drawn into doing some styling whenever Agile Web Development is working on it. Styling should really be left until functionality is hammered out, but I like this approach. I like messing around with padding, margins and color schemes. On the other hand, this ties into something I had wrong about coding for a long, long time. I always kind of assumed programmers had a lot more memorized than they do. Now it's apparent that coders memorize methods they use a lot, but still have to look up quite a bit of information. The important thing is understanding how an application works, having a plan to accomplish what you want done, and knowing how to find the specific information when you need it. So in that case, yes, this DOES pertain specifically to Rails and not just CSS!
I also ran across this page while I was searching for Jquery examples. Seems like a good resource.
Monday, July 4, 2011
Rails 3.1 Tutorials
But I just found some Rails 3.1 tutorials on Git the other day, and that sounds like a good choice, too.
Another Rails friend of mine (@SpencerCooley) was talking about how he feels more productive when he's less afraid of breaking his code. I've felt this way for a while now. Remember when I used to just restart an application as soon as I broke the code, because it was less of a hassle to repeat what I knew how to do than to figure out how to fix the things I didn't? How are you supposed to grow and develop working that way? You won't, dummy!
So now that I'm more experienced, I feel way more confident in my ability to not only figure out what is giving me an error, but I feel better equipped to go about trying to solve it. I've got a better grasp on how to talk about what I'm doing. You may have noticed I haven't been updating this blog as often lately. My higher level of confidence in my ability to solve my own problem is partly to blame for this. Still, I need to get back in the habit of updating my blog whenever I code, and I need to get back in the habit of coding every day. No more lazy Fridays, you hear me?
Also, I think I'm just going to use Twitter handles when referring to other Rails enthusiasts from now on.


