Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Welcome Controller

  • Loading branch information...
commit 8a0ba7608c62e9f025b1c69d853d262146e476f2 1 parent 7cb524f
Thiago Pradi authored
1  README.mkdn
View
@@ -5,6 +5,7 @@
<h2>Feature list: </h2>
<p> All writes will be sent to master, and the read queries will be sent to the slaves. unless you have a transaction, so , all queries will be sent to master.</p>
+<p> The application have two different models: Client and User. User is a replicated model, and Client isn't replicated. So, when you create a new User, you will see a exception, because you don't have configuration for replication and Rails tries to read the user from a slave database, and the write query have been sent to master (Default behaviour when using replication). When you create a new client, everything should works fine, it will read and write in the master database. </p>
<h2> Setup: </h2>
<p> You will need two commands to setup the application:</p>
4 app/controllers/welcome_controller.rb
View
@@ -0,0 +1,4 @@
+class WelcomeController < ApplicationController
+ def index
+ end
+end
2  app/helpers/welcome_helper.rb
View
@@ -0,0 +1,2 @@
+module WelcomeHelper
+end
6 app/views/welcome/index.html.erb
View
@@ -0,0 +1,6 @@
+<h1>Welcome to Octopus Replication Example!</h1>
+<p>Replicated Model:</p>
+<%= link_to "Users", users_path%>
+<p>Non-Replicated Model:</p>
+<%= link_to "Clients", clients_path%>
+
6 config/routes.rb
View
@@ -1,8 +1,8 @@
OctopusReplicationExample::Application.routes.draw do |map|
+ get "welcome/index"
resources :clients
-
resources :users
-
+ root :to => "welcome#index"
# The priority is based upon order of creation:
# first created -> highest priority.
@@ -49,10 +49,8 @@
# # (app/controllers/admin/products_controller.rb)
# resources :products
# end
-
# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
- # root :to => "welcome#index"
# See how all your routes lay out with "rake routes"
6 db/schema.rb
View
@@ -11,14 +11,16 @@
ActiveRecord::Schema.define(:version => 20100623041305) do
- create_table "clients", :force => true do |t|
+ create_table "clients", :id => false, :force => true do |t|
+ t.integer "id", :null => false
t.string "name"
t.date "birthday"
t.datetime "created_at"
t.datetime "updated_at"
end
- create_table "users", :force => true do |t|
+ create_table "users", :id => false, :force => true do |t|
+ t.integer "id", :null => false
t.string "name"
t.date "birthday"
t.datetime "created_at"
279 public/index.html
View
@@ -1,279 +0,0 @@
-<!DOCTYPE html>
-<html>
- <head>
- <title>Ruby on Rails: Welcome aboard</title>
- <style type="text/css" media="screen">
- body {
- margin: 0;
- margin-bottom: 25px;
- padding: 0;
- background-color: #f0f0f0;
- font-family: "Lucida Grande", "Bitstream Vera Sans", "Verdana";
- font-size: 13px;
- color: #333;
- }
-
- h1 {
- font-size: 28px;
- color: #000;
- }
-
- a {color: #03c}
- a:hover {
- background-color: #03c;
- color: white;
- text-decoration: none;
- }
-
-
- #page {
- background-color: #f0f0f0;
- width: 750px;
- margin: 0;
- margin-left: auto;
- margin-right: auto;
- }
-
- #content {
- float: left;
- background-color: white;
- border: 3px solid #aaa;
- border-top: none;
- padding: 25px;
- width: 500px;
- }
-
- #sidebar {
- float: right;
- width: 175px;
- }
-
- #footer {
- clear: both;
- }
-
-
- #header, #about, #getting-started {
- padding-left: 75px;
- padding-right: 30px;
- }
-
-
- #header {
- background-image: url("images/rails.png");
- background-repeat: no-repeat;
- background-position: top left;
- height: 64px;
- }
- #header h1, #header h2 {margin: 0}
- #header h2 {
- color: #888;
- font-weight: normal;
- font-size: 16px;
- }
-
-
- #about h3 {
- margin: 0;
- margin-bottom: 10px;
- font-size: 14px;
- }
-
- #about-content {
- background-color: #ffd;
- border: 1px solid #fc0;
- margin-left: -55px;
- margin-right: -10px;
- }
- #about-content table {
- margin-top: 10px;
- margin-bottom: 10px;
- font-size: 11px;
- border-collapse: collapse;
- }
- #about-content td {
- padding: 10px;
- padding-top: 3px;
- padding-bottom: 3px;
- }
- #about-content td.name {color: #555}
- #about-content td.value {color: #000}
-
- #about-content ul {
- padding: 0;
- list-style-type: none;
- }
-
- #about-content.failure {
- background-color: #fcc;
- border: 1px solid #f00;
- }
- #about-content.failure p {
- margin: 0;
- padding: 10px;
- }
-
-
- #getting-started {
- border-top: 1px solid #ccc;
- margin-top: 25px;
- padding-top: 15px;
- }
- #getting-started h1 {
- margin: 0;
- font-size: 20px;
- }
- #getting-started h2 {
- margin: 0;
- font-size: 14px;
- font-weight: normal;
- color: #333;
- margin-bottom: 25px;
- }
- #getting-started ol {
- margin-left: 0;
- padding-left: 0;
- }
- #getting-started li {
- font-size: 18px;
- color: #888;
- margin-bottom: 25px;
- }
- #getting-started li h2 {
- margin: 0;
- font-weight: normal;
- font-size: 18px;
- color: #333;
- }
- #getting-started li p {
- color: #555;
- font-size: 13px;
- }
-
-
- #search {
- margin: 0;
- padding-top: 10px;
- padding-bottom: 10px;
- font-size: 11px;
- }
- #search input {
- font-size: 11px;
- margin: 2px;
- }
- #search-text {width: 170px}
-
-
- #sidebar ul {
- margin-left: 0;
- padding-left: 0;
- }
- #sidebar ul h3 {
- margin-top: 25px;
- font-size: 16px;
- padding-bottom: 10px;
- border-bottom: 1px solid #ccc;
- }
- #sidebar li {
- list-style-type: none;
- }
- #sidebar ul.links li {
- margin-bottom: 5px;
- }
-
- </style>
- <script type="text/javascript">
- function about() {
- info = document.getElementById('about-content');
- if (window.XMLHttpRequest)
- { xhr = new XMLHttpRequest(); }
- else
- { xhr = new ActiveXObject("Microsoft.XMLHTTP"); }
- xhr.open("GET","rails/info/properties",false);
- xhr.send("");
- info.innerHTML = xhr.responseText;
- info.style.display = 'block'
- }
-
- function prepend() {
- search = document.getElementById('search-text');
- text = search.value;
- search.value = 'site:rubyonrails.org ' + text;
- }
-
- window.onload = function() {
- document.getElementById('search-text').value = '';
- }
- </script>
- </head>
- <body>
- <div id="page">
- <div id="sidebar">
- <ul id="sidebar-items">
- <li>
- <form id="search" action="http://www.google.com/search" method="get" onSubmit="prepend();">
- <input type="hidden" name="hl" value="en" />
- <input type="text" id="search-text" name="q" value="site:rubyonrails.org " />
- <input type="submit" value="Search" /> the Rails site
- </form>
- </li>
-
- <li>
- <h3>Join the community</h3>
- <ul class="links">
- <li><a href="http://www.rubyonrails.org/">Ruby on Rails</a></li>
- <li><a href="http://weblog.rubyonrails.org/">Official weblog</a></li>
- <li><a href="http://wiki.rubyonrails.org/">Wiki</a></li>
- </ul>
- </li>
-
- <li>
- <h3>Browse the documentation</h3>
- <ul class="links">
- <li><a href="http://api.rubyonrails.org/">Rails API</a></li>
- <li><a href="http://stdlib.rubyonrails.org/">Ruby standard library</a></li>
- <li><a href="http://corelib.rubyonrails.org/">Ruby core</a></li>
- <li><a href="http://guides.rubyonrails.org/">Rails Guides</a></li>
- </ul>
- </li>
- </ul>
- </div>
-
- <div id="content">
- <div id="header">
- <h1>Welcome aboard</h1>
- <h2>You&rsquo;re riding Ruby on Rails!</h2>
- </div>
-
- <div id="about">
- <h3><a href="rails/info/properties" onclick="about(); return false">About your application&rsquo;s environment</a></h3>
- <div id="about-content" style="display: none"></div>
- </div>
-
- <div id="getting-started">
- <h1>Getting started</h1>
- <h2>Here&rsquo;s how to get rolling:</h2>
-
- <ol>
- <li>
- <h2>Use <code>rails generate</code> to create your models and controllers</h2>
- <p>To see all available options, run it without parameters.</p>
- </li>
-
- <li>
- <h2>Set up a default route and remove or rename this file</h2>
- <p>Routes are set up in config/routes.rb.</p>
- </li>
-
- <li>
- <h2>Create your database</h2>
- <p>Run <code>rake db:migrate</code> to create your database. If you're not using SQLite (the default), edit <code>config/database.yml</code> with your username and password.</p>
- </li>
- </ol>
- </div>
- </div>
-
- <div id="footer">&nbsp;</div>
- </div>
- </body>
-</html>
12 spec/controllers/welcome_controller_spec.rb
View
@@ -0,0 +1,12 @@
+require 'spec_helper'
+
+describe WelcomeController do
+
+ describe "GET 'index'" do
+ it "should be successful" do
+ get 'index'
+ response.should be_success
+ end
+ end
+
+end
15 spec/helpers/welcome_helper_spec.rb
View
@@ -0,0 +1,15 @@
+require 'spec_helper'
+
+# Specs in this file have access to a helper object that includes
+# the WelcomeHelper. For example:
+#
+# describe WelcomeHelper do
+# describe "string concat" do
+# it "concats two strings with spaces" do
+# helper.concat_strings("this","that").should == "this that"
+# end
+# end
+# end
+describe WelcomeHelper do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
5 spec/views/welcome/index.html.erb_spec.rb
View
@@ -0,0 +1,5 @@
+require 'spec_helper'
+
+describe "welcome/index.html.erb" do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
Please sign in to comment.
Something went wrong with that request. Please try again.