background preloader

Rails Routing from the Outside In

Rails Routing from the Outside In
1 The Purpose of the Rails Router The Rails router recognizes URLs and dispatches them to a controller's action. It can also generate paths and URLs, avoiding the need to hardcode strings in your views. 1.1 Connecting URLs to Code When your Rails application receives an incoming request for: it asks the router to match it to a controller action. 1.2 Generating Paths and URLs from Code You can also generate paths and URLs. and your application contains this code in the controller: and this in the corresponding view: then the router will generate the path /patients/17. 2 Resource Routing: the Rails Default Resource routing allows you to quickly declare all of the common routes for a given resourceful controller. 2.1 Resources on the Web Browsers request pages from Rails by making a request for a URL using a specific HTTP method, such as GET, POST, PATCH, PUT and DELETE. it asks the router to map it to a controller action. 2.2 CRUD, Verbs, and Actions 2.3 Path and URL Helpers 2.5 Singular Resources

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

The Asset Pipeline 1 What is the Asset Pipeline? The asset pipeline provides a framework to concatenate and minify or compress JavaScript and CSS assets. It also adds the ability to write these assets in other languages and pre-processors such as CoffeeScript, Sass and ERB. The asset pipeline is technically no longer a core feature of Rails 4, it has been extracted out of the framework into the sprockets-rails gem. The asset pipeline is enabled by default. You can disable the asset pipeline while creating a new application by passing the --skip-sprockets option. Rails 4 automatically adds the sass-rails, coffee-rails and uglifier gems to your Gemfile, which are used by Sprockets for asset compression: Using the --skip-sprockets option will prevent Rails 4 from adding sass-rails and uglifier to Gemfile, so if you later want to enable the asset pipeline you will have to add those gems to your Gemfile. 1.1 Main Features The second feature of the asset pipeline is asset minification or compression. More reading:

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

Ruby on Rails Tutorial | Softcover.io Welcome to the Ruby on Rails Tutorial. The goal of this book is to be the best answer to the question, “If I want to learn web development with Ruby on Rails, where should I start?” By the time you finish the Ruby on Rails Tutorial, you will have all the skills you need to develop and deploy your own custom web applications with Rails. You will also be ready to benefit from the many more advanced books, blogs, and screencasts that are part of the thriving Rails educational ecosystem. Finally, since the Ruby on Rails Tutorial uses Rails 4, the knowledge you gain here represents the state of the art in web development. (The most up-to-date version of the Ruby on Rails Tutorial can be found on the book’s website at if you are reading this book offline, be sure to check the online version of the Rails Tutorial book at for the latest updates.) Box 1.1. Box 1.2. 1.1 Introduction What makes Rails so great? 1.1.2 “Scaling” Rails Browsers

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 }

Getting Started with Rails 1 Guide Assumptions This guide is designed for beginners who want to get started with a Rails application from scratch. It does not assume that you have any prior experience with Rails. Rails is a web application framework running on the Ruby programming language. Be aware that some resources, while still excellent, cover versions of Ruby as old as 1.6, and commonly 1.8, and will not include some syntax that you will see in day-to-day development with Rails. 2 What is Rails? Rails is a web application development framework written in the Ruby programming language. Rails is opinionated software. The Rails philosophy includes two major guiding principles: Don't Repeat Yourself: DRY is a principle of software development which states that "Every piece of knowledge must have a single, unambiguous, authoritative representation within a system." 3 Creating a New Rails Project The best way to read this guide is to follow it step by step. 3.1 Installing Rails Open up a command line prompt. 9 Security

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!

Ruby on Rails Guides

Related: