Best way to learn Ruby & Rails - @AstonJ's Blog
That’s no typo, I really did mean Ruby and Rails – but before you run off (those looking to learn only Rails) read on… I started off wanting to learn just Rails too, but I quickly realised two things: Rails will only get you so far – to be anything close to a Rails ninja, you need to learn Ruby (Rails is Ruby underneath it all). While Rails goes out of its way to simplify a lot, once you begin to do more complex stuff you’re going to need to know Ruby – and because Ruby is so easy to pick up anyway it makes sense to learn it from the outset. It will not only save you time in the long run, but will also help you learn Rails as well, because you’ll have a better understanding of what’s going on.Even if you came for Rails, most likely you will stay for Ruby – like so many of us! The more you’re exposed to Ruby the more you’ll want to learn it. If you’re only interested in learning Ruby, just skip over the Rails bits. Is there really a best way to learn Ruby & Rails? Look no affiliate links
4.5. Populating the Database with seeds.rb
With the file db/seeds.rb, the Rails gods have given us a way of feeding default values easily and quickly to a fresh installation. This is a normal Ruby program within the Rails environment. You have full access to all classes and methods of your application. So you do not need to enter everything manually with rails console in order to make the records created in the section called “create” available in a new Rails application, but you can simply use the following file db/seeds.rb: Country.create(name: 'Germany', population: 81831000) Country.create(name: 'France', population: 65447374) Country.create(name: 'Belgium', population: 10839905) Country.create(name: 'Netherlands', population: 16680000) You then populate it with data via rake db:seed. I use the file db/seeds.rb at this point because it offers a simple mechanism for filling an empty database with default values. Generating seeds.rb From Existing Data We create our own little rake task for that.
Ruby on Rails Tutorial: Learn Rails by Example book and screencasts by Michael Hartl
Michael Hartl Contents Foreword My former company (CD Baby) was one of the first to loudly switch to Ruby on Rails, and then even more loudly switch back to PHP (Google me to read about the drama). This book by Michael Hartl came so highly recommended that I had to try it, and the Ruby on Rails Tutorial is what I used to switch back to Rails again. Though I’ve worked my way through many Rails books, this is the one that finally made me “get” it. The linear narrative is such a great format. Enjoy! Derek Sivers (sivers.org) Founder, CD Baby Acknowledgments The Ruby on Rails Tutorial owes a lot to my previous Rails book, RailsSpace, and hence to my coauthor Aurelius Prochazka. I’d like to acknowledge a long list of Rubyists who have taught and inspired me over the years: David Heinemeier Hansson, Yehuda Katz, Carl Lerche, Jeremy Kemper, Xavier Noria, Ryan Bates, Geoffrey Grosenbach, Peter Cooper, Matt Aimonetti, Gregg Pollack, Wayne E. About the author Copyright and license 1.1 Introduction
Form Helpers
This guide is not intended to be a complete documentation of available form helpers and their arguments. Please visit the Rails API documentation for a complete reference. 1 Dealing with Basic Forms The most basic form helper is form_tag. When called without arguments like this, it creates a <form> tag which, when submitted, will POST to the current page. You'll notice that the HTML contains input element with type hidden. 1.1 A Generic Search Form One of the most basic forms you see on the web is a search form. a form element with "GET" method,a label for the input,a text input element, anda submit element. To create this form you will use form_tag, label_tag, text_field_tag, and submit_tag, respectively. This will generate the following HTML: For every form input, an ID attribute is generated from its name ("q" in above example). Besides text_field_tag and submit_tag, there is a similar helper for every form control in HTML. Always use "GET" as the method for search forms. 1.3.1 Checkboxes
Ruby on Rails 3 Testing with RSpec 2 | Jonathan Hui
Install Rspec-rails sudo gem install rspec-rails RSpec is a behavior driven development (BDD) framework for low level testing in the Ruby language Create a new Rails application store Edit the Gemfile Include the Cucumber gems in a Rails 3 application group :test, :development do gem "rspec-rails", "~> 2.4" gem 'capybara' end Install the Gems Edit the DB connection information and put the valid DB configuration information Create the MySQL DB rake db:create rake db:migrate Bootstrap a Rails 3 application with RSpec rails generate rspec:install create .rspec create spec create spec/spec_helper.rb Generate a model rails generate model order name:string invoke active_record create db/migrate/20110510190917_create_orders.rb create app/models/order.rb invoke rspec create spec/models/order_spec.rb Create the DB table General Syntax for RSpec describe "something" do it "does something" do ... end end Edit the RSpec Test vi spec/models/order_spec.rb Edit the RSpec testing code Smoke test let(:count) { @total += 1 }
Commencer avec Ruby on Rails
Ce guide s'inspire du site « Rails Guides », de mon expérience personnelle de Ruby on Rails et dans tout un tas d'autres ressources (screencasts, sites communautaires, etc...). Ce guide est également l'occasion de constituer une application de A à Z, d'en voir tous les tenants et les aboutissants (conception, codage, déploiement, etc...). Je vous souhaite d'ores et déjà une très bonne lecture ! Dans ce guide, je pars du principe que le lecteur possède une connaissance minimale du langage Ruby. Si certaines portions de code Ruby nécessitent des précisions, j'expliquerai le plus clairement possible ces points de détail. Pour commencer avec Ruby on Rails, il est nécessaire d'avoir au moins trois choses installées : Ruby (version 1.8.7 dans le cas de ce guide) Rubygems (version 1.3.2 dans le cas de ce guide) SQLite, MySQL, ou PostgreSQL Rails est un framework de développement web écrit en langage Ruby. La philosophie de Rails se base sur trois principes : III-A. III-B. IV-A. IV-B. IV-C.
The Best Way to Learn Rails
I come from a PHP background, but these days, I'm a full-time Rails developer. The difficulty for most people who make the switch lies in the learning curve that’s involved. Once you've become proficient in a language or framework, switching to a new one feels like an unnecessary (and time-consuming) challenge. However, learning Ruby and Rails is actually pretty easy! It's an incredibly powerful framework, and has a huge community pushing it along. So that begs the question: what's the best way to learn Rails? This article details a full lesson plan that will get you up and running in no time! You might think learning Ruby is the most important step, and this is probably the part where everyone stops learning and just sticks with their current framework. Work through the Try Ruby exercises. The most recommended tool for dipping into Ruby's syntax is the Try Ruby website. Once you’ve worked through these exercises a couple of times, you'll have a solid base. Great! Railscasts: A must!
Créer une interface graphique avec Ruby/GTK
Pour le moment, nous n'avons vu que la fenêtre, qui est un conteneur ne pouvant contenir qu'un seul widget. Il s'agissait du conteneur Gtk::Bin, dont Gtk::Window hérite. Mais ceci n'est pas suffisant pour faire une interface graphique, nous allons donc voir les autres conteneurs disponibles. Les boîtes sont un type de conteneur très simple, semblables à n'importe quel carton dans lequel on jette des revues : elles s'empilent les unes au dessus des autres, dans l'ordre dans lequel on les a jetées. Il existe des boîtes verticales (Gtk::VBox) et des boîtes horizontales (Gtk::HBox), qui héritent toutes les deux de l'objet générique Gtk::Box. Voyons quelques exemples de boîtes window = Gtk::Window.new window.set_title('VBox homogene') window.signal_connect('destroy') { Gtk.main_quit } vbox = Gtk::VBox.new(true, 6) vbox.pack_start(Gtk::Button.new('Un')) vbox.pack_start(Gtk::Button.new('Deux')) vbox.pack_start(Gtk::Button.new('Trois')) window.add(vbox) window.show_all