Hi friends,
This is the simple and sample application to create using rails and heroku is here. This post mostly covers 3rd part of the “Learn Rails By Example” book.
$ rails new sample app -T
$ rails generate controller Pages home contact
$ gedit Gemfile
Edit the file and add the following,
source 'http://rubygems.org' gem 'rails', '3.0.3' gem 'sqlite3-ruby', '1.3.2', :require => 'sqlite3' group :development do gem 'rspec-rails', '2.3.0' end group :test do gem 'rspec', '2.3.0' gem 'webrat', '0.7.1' gem 'spork' end
The Pages controller spec with a base title. spec/controllers/pages_controller_spec.rb
require 'spec_helper' describe PagesController do render_views describe "GET 'home'" do it "should be successful" do get 'home' response.should be_success end it "should have the right title" do get 'home' response.should have_selector("title", :content => "Ruby on Rails Sample App | Home") end end describe "GET 'contact'" do it "should be successful" do get 'contact' response.should be_success end it "should have the right title" do get 'contact' response.should have_selector("title", :content => "Ruby on Rails Sample App | Contact") end end describe "GET 'about'" do it "should be successful" do get 'about' response.should be_success end it "should have the right title" do get 'about' response.should have_selector("title", :content => "Ruby on Rails Sample App | About") end end end
The Pages controller with per-page titles.
app/controllers/pages_controller.rb
class PagesController < ApplicationController def home @title = "Home" end def contact @title = "Contact" end def about @title = "About" end end
The sample application site layout.
app/views/layouts/application.html.erb
<!DOCTYPE html> <html> <head> <title>Ruby on Rails Sample App | <%= @title %></title> <%= csrf_meta_tag %> </head> <body> <%= yield %> </body> </html>
The Home view with HTML structure removed.
app/views/pages/home.html.erb
<h1>Sample App</h1> <p> This is the home page for the <a href="http://thasulinux.wordpress.com/">My Blog Home page</a> sample application. </p>
The Contact view with HTML structure removed.
app/views/pages/contact.html.erb
<h1>Sample App</h1> <p> This is the about page for <a href="http://about.me/thasuresh/">Me</a> sample application. </p>
The About view with HTML structure removed.
app/views/pages/about.html.erb (This “about” page we ve to create manually)
<h1>About Me</h1> <p> Contact Ruby on Rails Tutorial about the sample app at the <a href="http://thasulinux.wordpress.com/about/">feedback page</a>. </p>
check out my sample project on-line at http://strong-sunrise-136.heroku.com/
In the url bar add this following “.com /” “pages/home” “pages/contact” “pages/about”
(i.e)
http://strong-sunrise-136.heroku.com/pages/home
http://strong-sunrise-136.heroku.com/pages/contact
http://strong-sunrise-136.heroku.com/pages/about
update:
(Now, those is url were not in use, try http://strong-sunrise-136.heroku.com/)
