Newbies: Help Me Help You

A good long while ago, Curt Hibbs (author of the original, famous, Slashdotted Rolling with Rails tutorial for ONLamp—who literally jumpstarted my Rails writing career) commented on one of my blog entries. Somebody was saying my content was only useful for utter noobs, and then the dude pimped someone else’s site for the more “advanced” readers who don’t find what I write “interesting.” Curt, gentleman that he is, responded to this person using his own comment:

Amy, there’s been plenty written for beginners so writing at the intermediate level (those who yearn for a deeper undertsanding) is excellent. Further, writing about area that frustrated or confused you [is] also good because others are likely to have had the same experience (plus later on you’ll forget about it as everything becomes more natural)…

And he was right—certainly, the amount of traffic I get to this web site (largely click-throughs once people read my very first article) proves that it’s an important angle. And I have largely forgotten about what tripped me up and hurt my wee little designer brain. Rails is natural to me now, and I wish I’d written more about it when it was all fresh and confusing.

Getting Back to Basics

But I have to shake off my higher-level understanding, if only for a while, if I want to write a really kickass book (especially since I’m trying a different approach than most). And I really do want to, and I’m working hard to do so.

I also know that nothing great is truly ever achieved alone. To that end, I’d love to know what tripped you up or is in the process of tripping you up. What just hasn’t gelled yet in your understanding of Rails? What confused you? What made you feel like you were wandering around without a map or even a compass? Post your questions here, or poke me on the #rubyonrails IRC channel (again: I’m eriberri on freenode).

My goal here isn’t to be strictly question-and-answer, so if it’s your painful memory of what took you a long time to understand in the past, that’s great too. And I can’t guarantee that I will address every confusing thing you post, but I’ll try.

Thank You

I also promise that I won’t stop writing on my blog just to save it all for my book, because that’d be turning my back on the very folks who made it possible for me to write a book in the first place. Even if you never comment here on any topic, envisioning you out there’s what led me to write and gave me a direction and a voice.

Thank you.

No Comments

  1. Your site and writings here have been very helpful to me. I am total begginer in programming, not just RoR. Only been doing XHTML/CSS so far and I have little insight to PHP. But here I found all kinds of useful stuff, both the cheatsheets and your articles about RoR. Maybe I’ll write up the stuff that bugged me the most and send you 🙂

    Thank you for this nice resource for begginers like me. I’ll be looking out for your book.

  2. David Mankin says:

    I’ll go first…

    What the heck is a Symbol? Don’t just say "It’s an atom" or "It’s like interning". These analogies (that are the answer that everybody/book/website gives) don’t do anything for me.

    Really, how is it different from a string? In Rails, why can I use symbols interchangeably with strings a lot of times, and then other times they just don’t work the same?

    Why is it: redirect_to :action => "my_action" and not any of these: redirect_to :action => :my_action redirect_to "action" => "my_action" redirect_to "action" => :my_action ?

    What’s the difference between flash[:success] = "Congratulations" and flash["success"] = "Congratulations"

    Or, beween value = @params["id"] and value = @params[:id]

    If Symbols "save memory", why would I ever use a string like "my_action"?

    Thanks, that’s been the question I’ve wondered about since day one without ever getting a good answer.

  3. Yes. The symbol question was probably the one of the hardest things for me to get used to when switching from PHP to Rails (I had prior experience with oop).

    From what I understand it’s pretty much just a saving memory thing. Every time you use a string it’s gets it’s own spot in memory, so if your program users the parameter "controller" 100 times then 100 different "controller" strings are written in memory, while :controller uses the same spot in memory every time.

    I think it is also faster to type (one less punctuation mark) and makes the code easier to read. In :controller => ‘foobar’ it’s clearer than :controller is the param and ‘foobar’ is the value, as opposed to ‘controller’ => ‘foobar’ which just looks confusing (why is a string pointing to another string?).

    Of course, I could have this all wrong. Anyone else have a better answer?

  4. Brasten Sager says:

    Firstly, I love the site. Been a Java developer for 7 years, picked up Ruby about 2 months ago, and I’m loving it, but it’s not a super easy transition. There is great insight here!

    Question: As a matter of convention, in Rails specifically, where do you put files that contain purely business logic? Like, processors and such. They definitely aren’t a model, they aren’t really controllers either, though that’s where I’ve been putting them. Maybe I’m doing it right and my interpretation of the word "controller" is too narrow.

  5. Kevin Clark says:

    David and Chris: I wrote an article a few months back to answer your questions about symbols. You can find it at http://glu.ttono.us/articles/2005/08/19/understanding-ruby-symbols.

  6. Matt says:

    I’m a few weeks into my first Rails project and things are going pretty well, and I feel pretty confident that I’ll be able to get my project working locally.

    What scares me is going live. I come from a design background and have next to no knowledge of server stuff. I’m used to PHP or Coldfusion where you just upload the files to the server and it works.

    When Rails talks about restarting servers and creating symlinks and deleting sessions and logs manually and all that jazz… I curl into the fetal position.

    Yet, there isn’t a ton of articles out there on this, so I assume it’s pretty easy stuff. But have no idea where to begin.

  7. I am going to repeat some stuff but anyway…

    • symbols (I’ve got both books [ruby+rails] and there’s no clear explanation, and like you I want to know why, otherwise I get a learning block)

    • deployment (why is it that every rails app [like typo, tracks] I’ve tried to install on my host fails? Plus rails deployment seems messy to me, I mean okay so you have the dev, test and production platform, you’ve got the tests and blah blah blah BUT… Why should all that be on my development platform? Maybe I am wrong but I don’t want my dev or tests platform to be on my production platform it seems untidy!). I think there should be a kind of export command that get your rails app lean and mean and ready for production or something like that.

    • static content (that may be a very stupid question but since you asked…) It seems that in rails either all is organized or either all goes into a database. So where do I put my flash files (don’t start me on web standards… Something that has 90% penetration IS a webstandard)?

    • cookies Why does Rails use light cookies (that are heavy on the server and require the memcache stuff if you go multiserver) instead of fat cookies (as seen in Advanced PHP Programming by George Schlossnagle)?

  8. Geert says:

    I actually would like some help in setting up a development environment to start looking and playing around with rails code from an open source project. I am one of those people who prefers to study exising code instead of just starting a silly hello world app. I am struggling with RADRails, Subversion, MySQL and WEBbrick at the moment.

  9. Amy Hoy says:

    Great start, guys! Keep it comin. And thanks.

    A few of these I will answer right away and I will be posting those as posts instead of comments.

  10. Alan Hynes says:

    One of the difficult things I’ve found about getting my head around RoR is what happens when your data source is not a database?

    It probably isn’t a big deal, but reading books and sites doesn’t give too much away. They assume you’ll always be working with a database backend, but at times a file structure is needed (say a configuration file?) that cannot be modelled well in a database (say the interface just needs to present information from something like an XML file and allow the user simple modifications of [say,] the text node information).

    I gather (without having done this) that this simply means that your model doesn’t inherit the activerecord class (but becomes a class of it’s own, or a subclass of File or whatever is appropriate).

    By not sub-classing activerecord, you lose any of the in-built methods it provides. I assume this is not a problem, but are these interface-type methods that need to be overridden (in your new non-activerecord model)? Digging through the RoR code is probably going to answer all of this, but I find the idea (and time) of acquinting myself with Ruby enough to understand the Rails code not possible.

    I’ve read the Ruby on rails book since it was in Beta and are looking forward to your ‘recipe’-type book. Any ETA?

  11. ant says:

    What’s your baseline or cutoff? For instance, I have about a month’s experience with ColdFusion/Access. A week of PHP/MySQL, and I’m playing around with and am really interested in RoRs. But I’ll probably have some pretty basic questions! Sometimes they’re database questions, sometimes it’s the @params[:id] thingy. I just don’t get how all these special words get magically filled with values!!

    Are these the kinds of questions you’re wanting to answer? If so, buy some more server space cause I’ve got a ton! 🙂

  12. Jon says:

    A problem I’ve had is using the "def self.blah" stuff in the models. I continually get confused by what needs to have a ‘self.’ and what doesn’t in the model.

    Another thing I get confused with is where to put functions that I want accessible in multiple places. For controllers, there seems to be the application.rb controller but what about models and views?

    And what are the public/protected/private stuff in the controllers/models/views?

    And how do I upgrade between rails releases without screwing up a working app?

  13. Kevin says:

    Coming from PHP, some of the "magical" aspects of Rails really had me scratching my head. You know, the things that Rails knows that it doesn’t seem possible for it to know, like:

    "You mean, there is a function called find_by_my_field_name? But, I, uuh… never defined that anywhere… Hrmmm."

    "How does it know that People is the plural of Person!?"

  14. Matt Platte says:

    Coming from PHP/database land I’m accustomed to writing lots of JOINs. The beginner examples don’t go there and the intermediate examples are… well, where are they? I have both books, Google, etc. It would help me bridge my understanding if I had some non-trivial, working examples.

    The first do-it-myself task was to build a couple of select boxes, pulling from my database. Seems to me like this would be a common example, even for the beginners, but apparently not. That took a couple of days to get over. Yeah, it’s truly amazing how such a simple thing can be such a show-stopper!

    What inhibits and slows me down is also what attracts me: I don’t want to write crappy code. I want to write idiomatic, not idiotic Ruby code. So I’m moving very slowly, trying to do things the Ruby way instead of my usual slap-dash approach.

    Of the very few "real" applications downloadable from RoR site, most are broken. Many of the remaining look rather un-Ruby-like to my eyes, especially that accounting application.

    Non-trivial, working examples is what would help me most.

  15. @Jon : that can be answered by getting your hands on the books (either physically or digitally)! Or by looking it in the "first Edition of Programming Ruby":http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_classes.html (that’s for the "public/protected/private stuff")

    Mostly what you have are Ruby questions, so do try either "Programming Ruby":http://www.ruby-doc.org/docs/ProgrammingRuby/ or "the Chunky Bacon":http://poignantguide.net/ruby/ (which is less overwhelming)

    As for upgrading (rankly I don’t know), but get on the irc channel and ask, they won’t bite, they didn’t bite me in anycase.

  16. Sean Smith says:

    I am working on a largish Rails project. As I know our database structure is going to change at some point, to reflect additions, I decided to switch to migrations sooner rather than later. This turned out to be a slight pain in the ass, requiring me to refactor several sections of code.

    Seeing as migrations are at least as understandable as SQL syntax, it might be beneficial to get new people to use it earlier, as it can result in a design that is compatible across multiple databases as well.

    I know a group in my area who want me to give a talk on what I have learned, and I am sure there are others that would find "The Why And How Of Writing Migrations" useful.

  17. Amy Hoy says:

    Wow. Didn’t expect this level of response, and especially such well-thought-out stuff. I have the smartest readers around, apparently 🙂 I was expecting lots of really basic questions, but this is even better.

    I’m workin on some answers for you guys, and you are definitely helping. 🙂

  18. Andie Nordgren says:

    The thing I can’t seem to understand is how I’m supposed to fit all these scaffolded peices together. All the examples I’ve seen are one-table applications that reside in a single subdirectory of your webserver. I don’t want one modified scaffold structure to be my entire applications, so how do I tie them together?

    Say I want an applications that handles groups, people and charachters. I make scaffolds for these three tables in my database. Where do I put my "frontpage" that is the entry to all these? Do I have to code it completely manual, and does it go in the "public" folder? I really don’t get the structure I’m supposed to use here.

  19. Peter says:

    I have exactly the same question as Andie. Have 7 models, and 7 controllers with scaffold code. I have my basic ‘admin’ site. Now the frontend. Came so far as putting my start page in public and from there connect to my controller. Can I make a new controller where I handle all the code for my front-end?

  20. Amy Hoy says:

    Peter & Andie:

    Two things. I’ll get more in-depth on this at a later date, but sounds like you guys need answers now so here we go 🙂

    1. Remember, scaffolding is just a temporary jump start!
    2. All controllers have access to all models, and a controller doesn’t require a model. So you can make a FrontPageController if you want and it can aggregate all the data you want.

    Please stay tuned for further programming 😉

  21. Richstyles says:

    I’m a total newbie to all things programming and have both the Ruby and Rails books. Maybe this question was written for me.

    Just my 2 pesos here but I think even beginners are ready for something that puts the core concepts in a more easy to understand framework. Just some points that came to mind for me.

    scaffold demonstrations I think too much weight on scaffolds mislead beginners. It took me a while for it to settle in my head that these are merely stubs.

    modelling a web app from the database up I’d really like to know how to model an application. What kinds of tables, foreign keys, and items are needed to get something done.

    where does it all start??? Where’s all the +magical_stuff+ that gets loaded into an application. How is it loaded into the application. What are the things that automatically come with rails, what needs to be written out.

    business logic Where is the main business logic in a typical rails app. Any practical ways to define the delineation of M.V.C. within an application.

  22. Peter says:

    ‘Please stay tuned for further programming’

    Thanks Amy,

    I like to add that I learned from your first article that ‘all controllers can read the models’ which was helpfull, because I knew I could make that ‘god’ controller. Don’t wanna get to religious here :-))

    But I don’t want to ‘DRY’ and want to do it the ‘Rails Way’. So I allready have this code that works in my ‘abc’ controller, but it checks the folder with my admin templates, and I dont want to mess around to much with layout directives and stuff.

    So now I copied the controller code I need and can put that in the new controller. There I can write my new views for my frontend. Easy. But is this the right way? First I thought of a new controller where I call the action from the controller that allready handled that, and use my views from the new controller. Or is copying that little controller code for your new one not considered ‘DRY’.

    Thanks in Advance. Peter

  23. James says:

    Deployment ->

    I understand most of what I have done on my localhost with Ruby on Rails etc… The one thing I am confused about and have not been able to try because the lack of getting a hosting account that has Rails is this…

    When you originally create your dir(ex. "rails program") it creates a dir etc… you then run your Rails server in that dir and when you do http://127.0.0.1:3000/ you get whatever it is you have done in /program/public So now assume we have made the entire program and are ready to move into Production mode… What exactly do I do at this point?

    Thanks for any Articles or Replies here 🙂

  24. Kevin Marsh says:

    For your book, maybe a ‘PHP Way’ or ‘J2EE Way’ of doing a few common tasks… and then show the ‘Ruby Way’

    Also, can I get a mention in print? 😉

  25. Phil says:

    Not specifically a Rails question but what would be helpful in trying to learn Ruby is comparing and contrasting the use of Mixins in Ruby with the use of Interfaces in Java/PHP.

  26. I think this is an excellent idea. Amy, I’m looking for just one person to help fill in the role of newbie helper on a new ruby blog on the O’Reilly Network.

    This, would be great for those (me) types of folks who don’t just ‘get’ rails. In fact, I’ve spoken with a number of distinguished programmers who thought of Rails as ‘hard’.

    Can I ask you to join this soon-to-be-blog in such as public forum without too much embarrassment ?

    Ping me @ steve@fooworks.com

    -Steve "sucks at programming" Mallett

  27. Scott says:

    Working with different database structures. for example: one to one, one to many, many to many

    acst_as_list, acts_as_tree, acts_as_nested_list

    add/edit/remove/display children/parents/siblings, move up/down,…

    Working with forms. Creating a "wizard" (working with mutiple forms) Working with sessions, cookies

  28. Chris says:

    Here’s my take…

    I am a PHP developer and love the idea of Rails.

    I have zero Ruby experience. I will learn.

    I’ve got the ‘Ruby in a Nutshell’ and ‘Agile Web Development with Rails’ books … read the latter of the two, so far.

    My question: where does a real project start?

    Scaffolding is nice for the first iteration … after that, it blows away your code.

    Also, it’s amazing that the Agile book relied on the scaffolding method without showing how to ‘start’ without it.

    I’m all geared-up for Rails … and no logical way to start.

    Am I alone?

    -Chris

  29. Andrew says:

    Well, I wrote that comment you mention, and I really should clarify that I only made it because an earlier commenter had specifically asked for more referneces to more advanced stuff. And I also wrote how important I thought your perspecive on Rails as a designer was–it’s mine, too–and how I hoped you’d explore it more in future writing!

    And lots of people are pimping your site elsewhere, too, so don’t be too quick to complain that I added a pointer to someone else’s in yours! The web, it’s all about links, ya see. 😉

    BTW, your older entries are getting a lot of comment spam.

  30. April says:

    If you’re still wondering about this, I have a couple…

    How to add variable values to arrays. In a situation where the results from a database query isn’t quite what I need, I’d like to iterate through what I have, run a little script, and stick the values in an array. It sounds incredibly easy but I’m having a horrible time with it.

    I second the "configuration file" example above. When my application needs some basic information (like the site name) that will change yearly if ever, where’s the best place for it?

    I also second the production on a webhost scenario. I eventually figured it out, but it would have been nice to see in a book. I had the added hurdle of not having SSH access on that host, too.

    What do you do when you want to edit something on a list? I mean, instead of viewing list then clicking "edit" beside one of them, I’d like to have the list, edit the fields right there, and click Submit. Actually doing it creates confusion with naming the form fields and I can’t figure out how to use an instance variable so the forms can autopopulate… and can’t figure out how to set the value manually on radio buttons.

    I’m always a great font of stupid problems with relatively obscure answers.

  31. Gonna have to give it a try…

  32. The content of your show is great, I really enjoy it!

  33. Well done, nice instructions…

  34. The content of your show is great, I really enjoy it.

  35. I thout to do it in my local version!

  36. Te Verde says:

    Very nice write up 🙂

  37. Well at last catched the problem.

  38. I was very dissapointed of this 🙁

  39. i am not sure as to why 🙁

  40. Spybot S says:

    That’s awesome.

  41. Just thought I’d make a note about a problem!

  42. But I’m not sure why 🙁

  43. H R Block says:

    i am not sure as to why 🙁

Hey, why not get a shiny
Freckle Time Tracking
account?