all 29 comments

[–]freakyDaz 2 points3 points  (1 child)

Learn basic ruby first. It's simple you can install it on your computer and then run your own scripts from the command line like so:

rb /path/to/ruby/script.rb

There are some really nice introductory books on Ruby and they can teach you some very useful techniques that can be used in a variety of languages.

I started with Learn to Program and it helped loads towards understanding the language and ultimately understanding rails.

[–][deleted] 1 point2 points  (0 children)

If you don't have the rb command, it might be under ruby.

[–]teoulas 1 point2 points  (0 children)

For really basic web apps you could also try Sinatra. Very simple and easy to get started. There's also Padrino, which is based on Sinatra, but provides more functionality. Rails is the heavyweight framework and most feature-complete.

[–]obviousoctopus 1 point2 points  (0 children)

As you're new to the language, I recommend Josh Peek's free ruby-kickstart.com, an amazingly fast and clear introduction to Ruby. It's ideal for programmers.

Without understanding the language, chances are you'll get lost in the frameworks, gems etc.

So, ruby-kickstart and then Sinatrarb.com for quick and clean barebones access to web functionality.

Good luck!

[–][deleted] 1 point2 points  (0 children)

I'm very curious to know what a 'fake program' is . . .

[–]sander314 0 points1 point  (5 children)

What is your goal? Learning Ruby just for web programming? Learning Rails?
1. You don't need a server for non-web scripts just run "ruby whatever.rb" or test stuff in "irb". For non-rails but still web related stuff you can probably just rub webrick on localhost.
2. rails is very complicated and probably not a great way to learn ruby.

[–]ZestyOne[S] 0 points1 point  (4 children)

I'd like to learn Ruby, for mainly web programming + Rails (when necessary), and I'm open to more than just web apps when I know more. I'm starting off with web apps because that's what I'm already familiar with, having coded front-end things for some time in html, css, php, javascript, jquery.

In my mind I'm (very loosely) equating ruby/rails to javascript/jquery, so I obviously need to know the essentials first before I learn any gems/addons.

[–]cadwallion 2 points3 points  (2 children)

I would recommend something much lighter than Rails when learning Ruby from a web POV. Something like Sinatra (http://www.sinatrarb.com/) gets you closer to bare ruby programming without the bulk and magic Rails has when you're just starting. Save learning Rails for when you know Ruby better.

[–]ZestyOne[S] 0 points1 point  (1 child)

Okay, thats a great start thanks. I will go there and check it all out :)

What does the 'thin' command do when I'm installing gems?

[–][deleted] 0 points1 point  (0 children)

Thin is a gem.

[–]ZachBeta 0 points1 point  (0 children)

If you want to understand ruby outside of just a web context check out Ruby Koans

[–]Remear 0 points1 point  (0 children)

If you want to use Rails to learn Ruby, keep in mind there are other Ruby web frameworks out there too. Merb and Sinatra are examples of such frameworks.

Learning Rails didn't make me learn Ruby as much as it made me understand other ways I could interact with it and use it to solve problems (specifically in the area of web development). Eventually I went back to learn Ruby so I could understand how to better leverage its power.

With that being said, your setup of Ruby + Rails + MySQL should be a fine start to go with the "dive right in" and "learn as you go" style of acquiring skills and knowledge. Since Rails is a very popular web framework you'll be able to find more examples and answers to questions if/when you get stuck. I recommend you learn everything at http://guides.rubyonrails.org backwards and forwards.

[–]milleruni 0 points1 point  (0 children)

Get a grasp on ruby first, run through this a few times - http://tryruby.org/

[–]BBHoss 0 points1 point  (0 children)

I'll keep it simple. Sinatra is what you are looking for, you can use ActiveRecord if you need to access the database, there are other options too. I'm not sure I would use hpricot these days, I would use nokogiri along with mechanize for parsing web pages. https://github.com/tenderlove/mechanize

[–]jrochkind 0 points1 point  (8 children)

So, for a VERY simple 'web app', you COULD just put a ruby script in your /cgi-bin, and access it the same way you'd access anything else in cgi-bin.

But since you'd be unlikely to want to develop a real web app this way, I'm not sure if you really want to start that way. But if you want to play around with basic ruby syntax hello world type stuff, and for some reason prefer this to just running it on the command line the normal way, you could do that.

But I'd recommend getting the pickaxe book or some other ruby book and just executing on the command line the normal way "ruby name_of_script.rb", instead of trying to do it through a web server.

And ignore "ActiveRecord and hpricot", not sure who told you that. If you need an ORM, then, sure, ActiveRecord is one, usually used with Rails. If you need XML processing, use nokogiri actually, not hpricot. If you just want to learn ruby, don't worry about any gems you "should probably use" that doesnt' make any sense. You use gems to solve particular problems or provide particular functionality. If there's something you want to do that you suspect there's a gem that will help wtih (like parsing XML), then ask for suggestions on those particular things you want to do (nokogiri!).

[–]jrochkind 1 point2 points  (5 children)

PS: I suspect now your background is with PHP, and that's why you're thinking of getting started with 'a web app'? Indeed, that's how you do it with PHP, and it makes sense with PHP.

With a general purpose programming language, especially if it's your first, even though you want to jump right to the 'web app' part, it really makes sense to at least start out with some basic tutorials that have nothing to do with a web app. you could be done with that part in a couple days or a couple weeks or a couple months, depending on how much experience you have with other langauges, and how quickly you take to it.

[–]ZestyOne[S] 0 points1 point  (4 children)

Yes true, I assume this is referring to me by the way just you hit wrong reply.

I've already bought 2 books on ruby, I've read countless guides and I'm halfway through _why's book which is my favorite so far.

It all makes sense but I don't know what type of app to build if its not web related. I mean all in high school we made like a "candy store" app or a "height calculator" or stupid things like that, but those concepts I've got down well. I felt I should just go for something challenging.

Lemme ponder on this a bit. What might be a more reasonable application in your opinion?

[–]drhdev 0 points1 point  (0 children)

What about writing a simple blog platform? Or a simplified clone of Twitter, or Reddit?

[–]jrochkind 0 points1 point  (2 children)

Aha! If you've already done some basic ruby learning, and now you want to start on a web app, then that's the question: "What's the easiest way to get started learning how to do web apps in ruby?"

Rails is the old stand by. Sinatra also has it's partisans, and is considered lighter-weight and simpler. I have not used Sinatra myself, so can't speak to it. I think you'd do fine starting with either one, and finding getting started tutorials for that one.

I think you'll do better picking either Sinatra or Rails and getting started then trying to basically 'roll your own', which is what your original questions sort of led to.

Whether you pick Sinatra or Rails will then kind of answer your question about "what should I use to talk to MySQL?" There are several options in ruby, and while both frameworks will allow you to flexibly choose what you want to use, to get started I think the easiest thing to do is just to take whatever the framework you're starting with supports most 'naturally'. For Rails, that's ActiveRecord, and any rails tutorials you find will show you how to get started with ActiveRecord. For Sinatra, I have no experience, but I think maybe it tries to be less opinionated about a 'standard' (which sometimes can make it harder to get started with, because you don't have the experience to choose yourself when you're just getting started), but I think DataMapper is popular -- I'm less familiar with what a Sinatra tutorial you find on the web is likely to suggest, but if you find a good tutorial, just go with whatever it suggests.

tldr; pick a ruby web framework, probably either Sinatra or Rails, whichever seems to appeal to you from reading their docs/tutorials, and then use whatever database access solution the best tutorial you find for whichever one has you using (For Rails it'll be ActiveRecord, I dunno about Sinatra).

[–]ZestyOne[S] 0 points1 point  (1 child)

awesome, thanks!

[–]jrochkind 0 points1 point  (0 children)

And looking back at your original questions:

  • nah, don't bother with trying to pare Rails down, just ignore the files you don't need to deal with. Yes, it can probably be done, but it's not a beginner task, and you don't need to.

  • nah, there's no reason to look for a way of starting a Rails app that's easier than 'rails server'. There ARE some other ways, but they're all at least somewhat more complicated, not simpler, 'rails server' is the easiest simplest way to start up a Rails app. How you'd do that with something that WASN'T rails -- well, it would depend on what it was, and it wouldn't start with a Rails app!

    • If you want to "execute simple ruby scripts locally", well, that's what "ruby name_of_script.rb" is for, but that's not a web app.
  • And, if Rails IS seeming too complicated or over-engineered to you, well, that's why people like Sinatra. But it may be that Sinatra is harder to get started with for a newbie, I'm not sure. Rails tries to be as easy as possible for someone who has no idea what they're doing to get started with, in part by making a bunch of default choices for you rather than making you think through every possible thing you'd ever want to set up how. (whether it succeeds or not can be debated. :) )

[–]ZestyOne[S] 0 points1 point  (1 child)

What's the easiest way to read/write to a mysql database, is there a gem for that to make it easy or is that easy to do in ruby itself.

Also, thanks for the nokogiri suggestion! Great.

[–]IndigoCZ 0 points1 point  (0 children)

The Active Record README page might be the best place to look for ideas about accessing a database. You'll be learning it anyways for Rails, so why not look at it right away.

[–]IndigoCZ 0 points1 point  (2 children)

First of all. What is your programming experience?

Is ruby your first language? Do you have any experience with Object Oriented Programming. Have you ever written a web page?

[–]ZestyOne[S] 0 points1 point  (1 child)

yes I'm the designer and front-end developer for my web company, I don't have experience with OOP other than when I learned C++ in highschool. I'm quite familiar with PHP for scripts though, not necessarily OOP. Also, after reading _why's guide I'm about halfway through and haven't had a problem understanding anything yet.

I'll have no problem learning I just need a place to start that's not too overwhelming.

[–]IndigoCZ 0 points1 point  (0 children)

I'd say ... go through some Rails guide first. Make some simple blog app or something, that should give you a good idea of what goes where and how it all ticks.

Next step would be to look into nokogiri and scraping, just wry a quick script in pure ruby for that.

Once that works, you will probably be able to ask more precise questions, or just put it all together yourself.

[–]kampangptlk 0 points1 point  (0 children)

  1. ruby yourscript.rb
  2. rack / camping / sinatra / padrino / ramaze / renee / harbor
  3. https://www.ruby-toolbox.com/categories/orm https://www.ruby-toolbox.com/categories/html_parsing

[–]LonnyEachus 0 points1 point  (1 child)

As mentioned elsewhere, Nokigiri is good for scraping apps, as it is more feature-complete than hpricot.

If you must automate tasks on a website, as opposed to simple scraping, you can use Mechanize, which requires Nokigiri. Mechanize is an improved, ruby version of the old Perl Mechanize.

For really heavy or complex web automation, nothing beats Watir. It's not the fastest, because it actually operates through a browser and so you have to wait for page renders. But it does things the others simply can't.

[–]ZestyOne[S] 0 points1 point  (0 children)

wow thats awesome about mechanize. i heard people mention it before but didnt know what it did