Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

draft

  • Loading branch information...
commit df930c8f8c53449e514d545823e10a18cd0406cf 1 parent 4d711a9
@mrb authored
View
244 README
@@ -1,243 +1,3 @@
-== Welcome to Rails
+== Sammy on Rails
-Rails is a web-application framework that includes everything needed to create
-database-backed web applications according to the Model-View-Control pattern.
-
-This pattern splits the view (also called the presentation) into "dumb" templates
-that are primarily responsible for inserting pre-built data in between HTML tags.
-The model contains the "smart" domain objects (such as Account, Product, Person,
-Post) that holds all the business logic and knows how to persist themselves to
-a database. The controller handles the incoming requests (such as Save New Account,
-Update Product, Show Post) by manipulating the model and directing data to the view.
-
-In Rails, the model is handled by what's called an object-relational mapping
-layer entitled Active Record. This layer allows you to present the data from
-database rows as objects and embellish these data objects with business logic
-methods. You can read more about Active Record in
-link:files/vendor/rails/activerecord/README.html.
-
-The controller and view are handled by the Action Pack, which handles both
-layers by its two parts: Action View and Action Controller. These two layers
-are bundled in a single package due to their heavy interdependence. This is
-unlike the relationship between the Active Record and Action Pack that is much
-more separate. Each of these packages can be used independently outside of
-Rails. You can read more about Action Pack in
-link:files/vendor/rails/actionpack/README.html.
-
-
-== Getting Started
-
-1. At the command prompt, start a new Rails application using the <tt>rails</tt> command
- and your application name. Ex: rails myapp
-2. Change directory into myapp and start the web server: <tt>script/server</tt> (run with --help for options)
-3. Go to http://localhost:3000/ and get "Welcome aboard: You're riding the Rails!"
-4. Follow the guidelines to start developing your application
-
-
-== Web Servers
-
-By default, Rails will try to use Mongrel if it's are installed when started with script/server, otherwise Rails will use WEBrick, the webserver that ships with Ruby. But you can also use Rails
-with a variety of other web servers.
-
-Mongrel is a Ruby-based webserver with a C component (which requires compilation) that is
-suitable for development and deployment of Rails applications. If you have Ruby Gems installed,
-getting up and running with mongrel is as easy as: <tt>gem install mongrel</tt>.
-More info at: http://mongrel.rubyforge.org
-
-Say other Ruby web servers like Thin and Ebb or regular web servers like Apache or LiteSpeed or
-Lighttpd or IIS. The Ruby web servers are run through Rack and the latter can either be setup to use
-FCGI or proxy to a pack of Mongrels/Thin/Ebb servers.
-
-== Apache .htaccess example for FCGI/CGI
-
-# General Apache options
-AddHandler fastcgi-script .fcgi
-AddHandler cgi-script .cgi
-Options +FollowSymLinks +ExecCGI
-
-# If you don't want Rails to look in certain directories,
-# use the following rewrite rules so that Apache won't rewrite certain requests
-#
-# Example:
-# RewriteCond %{REQUEST_URI} ^/notrails.*
-# RewriteRule .* - [L]
-
-# Redirect all requests not available on the filesystem to Rails
-# By default the cgi dispatcher is used which is very slow
-#
-# For better performance replace the dispatcher with the fastcgi one
-#
-# Example:
-# RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
-RewriteEngine On
-
-# If your Rails application is accessed via an Alias directive,
-# then you MUST also set the RewriteBase in this htaccess file.
-#
-# Example:
-# Alias /myrailsapp /path/to/myrailsapp/public
-# RewriteBase /myrailsapp
-
-RewriteRule ^$ index.html [QSA]
-RewriteRule ^([^.]+)$ $1.html [QSA]
-RewriteCond %{REQUEST_FILENAME} !-f
-RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
-
-# In case Rails experiences terminal errors
-# Instead of displaying this message you can supply a file here which will be rendered instead
-#
-# Example:
-# ErrorDocument 500 /500.html
-
-ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"
-
-
-== Debugging Rails
-
-Sometimes your application goes wrong. Fortunately there are a lot of tools that
-will help you debug it and get it back on the rails.
-
-First area to check is the application log files. Have "tail -f" commands running
-on the server.log and development.log. Rails will automatically display debugging
-and runtime information to these files. Debugging info will also be shown in the
-browser on requests from 127.0.0.1.
-
-You can also log your own messages directly into the log file from your code using
-the Ruby logger class from inside your controllers. Example:
-
- class WeblogController < ActionController::Base
- def destroy
- @weblog = Weblog.find(params[:id])
- @weblog.destroy
- logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
- end
- end
-
-The result will be a message in your log file along the lines of:
-
- Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1
-
-More information on how to use the logger is at http://www.ruby-doc.org/core/
-
-Also, Ruby documentation can be found at http://www.ruby-lang.org/ including:
-
-* The Learning Ruby (Pickaxe) Book: http://www.ruby-doc.org/docs/ProgrammingRuby/
-* Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
-
-These two online (and free) books will bring you up to speed on the Ruby language
-and also on programming in general.
-
-
-== Debugger
-
-Debugger support is available through the debugger command when you start your Mongrel or
-Webrick server with --debugger. This means that you can break out of execution at any point
-in the code, investigate and change the model, AND then resume execution!
-You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'
-Example:
-
- class WeblogController < ActionController::Base
- def index
- @posts = Post.find(:all)
- debugger
- end
- end
-
-So the controller will accept the action, run the first line, then present you
-with a IRB prompt in the server window. Here you can do things like:
-
- >> @posts.inspect
- => "[#<Post:0x14a6be8 @attributes={\"title\"=>nil, \"body\"=>nil, \"id\"=>\"1\"}>,
- #<Post:0x14a6620 @attributes={\"title\"=>\"Rails you know!\", \"body\"=>\"Only ten..\", \"id\"=>\"2\"}>]"
- >> @posts.first.title = "hello from a debugger"
- => "hello from a debugger"
-
-...and even better is that you can examine how your runtime objects actually work:
-
- >> f = @posts.first
- => #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
- >> f.
- Display all 152 possibilities? (y or n)
-
-Finally, when you're ready to resume execution, you enter "cont"
-
-
-== Console
-
-You can interact with the domain model by starting the console through <tt>script/console</tt>.
-Here you'll have all parts of the application configured, just like it is when the
-application is running. You can inspect domain models, change values, and save to the
-database. Starting the script without arguments will launch it in the development environment.
-Passing an argument will specify a different environment, like <tt>script/console production</tt>.
-
-To reload your controllers and models after launching the console run <tt>reload!</tt>
-
-== dbconsole
-
-You can go to the command line of your database directly through <tt>script/dbconsole</tt>.
-You would be connected to the database with the credentials defined in database.yml.
-Starting the script without arguments will connect you to the development database. Passing an
-argument will connect you to a different database, like <tt>script/dbconsole production</tt>.
-Currently works for mysql, postgresql and sqlite.
-
-== Description of Contents
-
-app
- Holds all the code that's specific to this particular application.
-
-app/controllers
- Holds controllers that should be named like weblogs_controller.rb for
- automated URL mapping. All controllers should descend from ApplicationController
- which itself descends from ActionController::Base.
-
-app/models
- Holds models that should be named like post.rb.
- Most models will descend from ActiveRecord::Base.
-
-app/views
- Holds the template files for the view that should be named like
- weblogs/index.html.erb for the WeblogsController#index action. All views use eRuby
- syntax.
-
-app/views/layouts
- Holds the template files for layouts to be used with views. This models the common
- header/footer method of wrapping views. In your views, define a layout using the
- <tt>layout :default</tt> and create a file named default.html.erb. Inside default.html.erb,
- call <% yield %> to render the view using this layout.
-
-app/helpers
- Holds view helpers that should be named like weblogs_helper.rb. These are generated
- for you automatically when using script/generate for controllers. Helpers can be used to
- wrap functionality for your views into methods.
-
-config
- Configuration files for the Rails environment, the routing map, the database, and other dependencies.
-
-db
- Contains the database schema in schema.rb. db/migrate contains all
- the sequence of Migrations for your schema.
-
-doc
- This directory is where your application documentation will be stored when generated
- using <tt>rake doc:app</tt>
-
-lib
- Application specific libraries. Basically, any kind of custom code that doesn't
- belong under controllers, models, or helpers. This directory is in the load path.
-
-public
- The directory available for the web server. Contains subdirectories for images, stylesheets,
- and javascripts. Also contains the dispatchers and the default HTML files. This should be
- set as the DOCUMENT_ROOT of your web server.
-
-script
- Helper scripts for automation and generation.
-
-test
- Unit and functional tests along with fixtures. When using the script/generate scripts, template
- test files will be generated for you and placed in this directory.
-
-vendor
- External libraries that the application depends on. Also includes the plugins subdirectory.
- If the app has frozen rails, those gems also go here, under vendor/rails/.
- This directory is in the load path.
+A demo application from "a blog post":http://mrb.github.com
View
4 app/controllers/posts_controller.rb
@@ -3,7 +3,9 @@ class PostsController < ApplicationController
def index
@posts = Post.all
- respond_with(@posts)
+ respond_with(@posts) do |format|
+ format.js { render :layout => false}
+ end
end
def show
View
4 app/views/layouts/application.haml
@@ -7,5 +7,7 @@
=javascript_include_tag "jquery.js","sammy.js","sammyonrails.js"
%body
#home
- =yield
+ #left
+ =yield
+ #right
View
15 app/views/posts/_form.html.erb
@@ -1,15 +0,0 @@
-<% form_for(@post) do |f| %>
- <%= f.error_messages %>
-
- <div class="field">
- <%= f.label :title %><br />
- <%= f.text_field :title %>
- </div>
- <div class="field">
- <%= f.label :body %><br />
- <%= f.text_area :body %>
- </div>
- <div class="actions">
- <%= f.submit %>
- </div>
-<% end %>
View
6 app/views/posts/edit.html.erb
@@ -1,6 +0,0 @@
-<h1>Editing post</h1>
-
-<%= render 'form' %>
-
-<%= link_to 'Show', @post %> |
-<%= link_to 'Back', posts_path %>
View
4 app/views/posts/index.haml
@@ -0,0 +1,4 @@
+-@posts.each do |post|
+ %div{:id => "post_#{post.id}", :class => 'post'}
+ .title
+ %a{:href=>"#/posts/#{post.id}"}=post.title
View
25 app/views/posts/index.html.erb
@@ -1,25 +0,0 @@
-<h1>Listing posts</h1>
-
-<table>
- <tr>
- <th>Title</th>
- <th>Body</th>
- <th></th>
- <th></th>
- <th></th>
- </tr>
-
-<% @posts.each do |post| %>
- <tr>
- <td><%= post.title %></td>
- <td><%= post.body %></td>
- <td><%= link_to 'Show', "#/#{post.id}" %></td>
- <td><%= link_to 'Edit', edit_post_path(post) %></td>
- <td><%= link_to 'Destroy', post, :confirm => 'Are you sure?', :method => :delete %></td>
- </tr>
-<% end %>
-</table>
-
-<br />
-
-<%= link_to 'New post', new_post_path %>
View
5 app/views/posts/new.html.erb
@@ -1,5 +0,0 @@
-<h1>New post</h1>
-
-<%= render 'form' %>
-
-<%= link_to 'Back', posts_path %>
View
58 config/routes.rb
@@ -1,60 +1,4 @@
Sammyonrails::Application.routes.draw do |map|
resources :posts
-
- # The priority is based upon order of creation:
- # first created -> highest priority.
-
- # Sample of regular route:
- # match 'products/:id' => 'catalog#view'
- # Keep in mind you can assign values other than :controller and :action
-
- # Sample of named route:
- # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
- # This route can be invoked with purchase_url(:id => product.id)
-
- # Sample resource route (maps HTTP verbs to controller actions automatically):
- # resources :products
-
- # Sample resource route with options:
- # resources :products do
- # member do
- # get :short
- # post :toggle
- # end
- #
- # collection do
- # get :sold
- # end
- # end
-
- # Sample resource route with sub-resources:
- # resources :products do
- # resources :comments, :sales
- # resource :seller
- # end
-
- # Sample resource route with more complex sub-resources
- # resources :products do
- # resources :comments
- # resources :sales do
- # get :recent, :on => :collection
- # end
- # end
-
- # Sample resource route within a namespace:
- # namespace :admin do
- # # Directs /admin/products/* to Admin::ProductsController
- # # (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"
-
- # This is a legacy wild controller route that's not recommended for RESTful applications.
- # Note: This route will make all actions in every controller accessible via GET requests.
- # match ':controller(/:action(/:id(.:format)))'
+ root :to => "posts#index", :format => "js"
end
View
2  public/javascripts/application.js
@@ -1,2 +0,0 @@
-// Place your application-specific JavaScript functions and classes here
-// This file is automatically included by javascript_include_tag :defaults
View
110 public/javascripts/rails.js
@@ -1,110 +0,0 @@
-document.observe("dom:loaded", function() {
- var authToken = $$('meta[name=csrf-token]').first().readAttribute('content'),
- authParam = $$('meta[name=csrf-param]').first().readAttribute('content'),
- formTemplate = '<form method="#{method}" action="#{action}">\
- #{realmethod}<input name="#{param}" value="#{token}" type="hidden">\
- </form>',
- realmethodTemplate = '<input name="_method" value="#{method}" type="hidden">';
-
- function handleRemote(element) {
- var method, url, params;
-
- if (element.tagName.toLowerCase() == 'form') {
- method = element.readAttribute('method') || 'post';
- url = element.readAttribute('action');
- params = element.serialize(true);
- } else {
- method = element.readAttribute('data-method') || 'get';
- // TODO: data-url support is going away, just use href
- url = element.readAttribute('data-url') || element.readAttribute('href');
- params = {};
- }
-
- var event = element.fire("ajax:before");
- if (event.stopped) return false;
-
- new Ajax.Request(url, {
- method: method,
- parameters: params,
- asynchronous: true,
- evalScripts: true,
-
- onLoading: function(request) { element.fire("ajax:loading", {request: request}); },
- onLoaded: function(request) { element.fire("ajax:loaded", {request: request}); },
- onInteractive: function(request) { element.fire("ajax:interactive", {request: request}); },
- onComplete: function(request) { element.fire("ajax:complete", {request: request}); },
- onSuccess: function(request) { element.fire("ajax:success", {request: request}); },
- onFailure: function(request) { element.fire("ajax:failure", {request: request}); }
- });
-
- element.fire("ajax:after");
- }
-
- $(document.body).observe("click", function(event) {
- var message = event.element().readAttribute('data-confirm');
- if (message && !confirm(message)) {
- event.stop();
- return false;
- }
-
- var element = event.findElement("a[data-remote=true]");
- if (element) {
- handleRemote(element);
- event.stop();
- }
-
- var element = event.findElement("a[data-method]");
- if (element && element.readAttribute('data-remote') != 'true') {
- var method = element.readAttribute('data-method'),
- piggyback = method.toLowerCase() != 'post',
- formHTML = formTemplate.interpolate({
- method: 'POST',
- realmethod: piggyback ? realmethodTemplate.interpolate({ method: method }) : '',
- action: element.readAttribute('href'),
- token: authToken,
- param: authParam
- });
-
- var form = new Element('div').update(formHTML).down().hide();
- this.insert({ bottom: form });
-
- form.submit();
- event.stop();
- }
- });
-
- // TODO: I don't think submit bubbles in IE
- $(document.body).observe("submit", function(event) {
- var message = event.element().readAttribute('data-confirm');
- if (message && !confirm(message)) {
- event.stop();
- return false;
- }
-
- var inputs = event.element().select("input[type=submit][data-disable-with]");
- inputs.each(function(input) {
- input.disabled = true;
- input.writeAttribute('data-original-value', input.value);
- input.value = input.readAttribute('data-disable-with');
- });
-
- var element = event.findElement("form[data-remote=true]");
- if (element) {
- handleRemote(element);
- event.stop();
- }
- });
-
- $(document.body).observe("ajax:complete", function(event) {
- var element = event.element();
-
- if (element.tagName.toLowerCase() == 'form') {
- var inputs = element.select("input[type=submit][disabled=true][data-disable-with]");
- inputs.each(function(input) {
- input.value = input.readAttribute('data-original-value');
- input.writeAttribute('data-original-value', null);
- input.disabled = false;
- });
- }
- });
-});
View
37 public/javascripts/sammyonrails.js
@@ -1,29 +1,38 @@
(function($) {
var app = $.sammy(function() {
this.element_selector = "#home";
- // This is the body of your application
-
- // Home Page Route
- this.get('#/', function(){
-
+
+ this.helpers({
+ clear_right: function(){
+ $("#right").html('');
+ }
+ })
+
+ this.before(function(){
+ this.clear_right();
+ });
+
+ this.get('#/:model/:id', function(){
+ var model = this.params['model'];
+ var id = this.params['id'];
+ $.get("/"+model+"/"+id+'.js',function(response){
+ $("#right").html(response);
+ });
});
- this.get('#/:id', function(){
- $.get("/posts/"+this.params['id']+".js",function(response){
- $("#home").append(response);
+ this.get('#/:model', function(){
+ var model = this.params['model'];
+ $.get("/"+model+".js",function(response){
+ $("#left").html(response);
});
});
this.bind('run', function(){
- // 'run' is one of the custom events that you can bind to within a
- // Sammy application. Use it to set up your application. I use it to
- // bind forms with jQuery form, setup common behaviors, etc.
- var context = this;
+ $("home").html('');
});
});
$(function() {
- // When the application runs, the #/ route will be executed
- app.run('#/');
+ app.run('#/posts');
});
})(jQuery);
View
27 public/stylesheets/sammyonrails.css
@@ -0,0 +1,27 @@
+body { background-color: #fff; color: #333; }
+
+body, p, ol, ul, td {
+ font-family: verdana, arial, helvetica, sans-serif;
+ font-size: 13px;
+ line-height: 18px;
+}
+
+pre {
+ background-color: #eee;
+ padding: 10px;
+ font-size: 11px;
+}
+
+a { color: #000; }
+a:visited { color: #666; }
+a:hover { color: #fff; background-color:#000; }
+
+#left{
+ float:left;
+ width:20%;
+}
+
+#right{
+ float:left;
+ width:80%;
+}
View
0  public/stylesheets/sammyonrails.js
No changes.
View
61 public/stylesheets/scaffold.css
@@ -1,61 +0,0 @@
-body { background-color: #fff; color: #333; }
-
-body, p, ol, ul, td {
- font-family: verdana, arial, helvetica, sans-serif;
- font-size: 13px;
- line-height: 18px;
-}
-
-pre {
- background-color: #eee;
- padding: 10px;
- font-size: 11px;
-}
-
-a { color: #000; }
-a:visited { color: #666; }
-a:hover { color: #fff; background-color:#000; }
-
-div.field, div.actions {
- margin-bottom: 10px;
-}
-
-.notice {
- color: green;
-}
-
-.fieldWithErrors {
- padding: 2px;
- background-color: red;
- display: table;
-}
-
-#errorExplanation {
- width: 400px;
- border: 2px solid red;
- padding: 7px;
- padding-bottom: 12px;
- margin-bottom: 20px;
- background-color: #f0f0f0;
-}
-
-#errorExplanation h2 {
- text-align: left;
- font-weight: bold;
- padding: 5px 5px 5px 15px;
- font-size: 12px;
- margin: -7px;
- background-color: #c00;
- color: #fff;
-}
-
-#errorExplanation p {
- color: #333;
- margin-bottom: 0;
- padding: 5px;
-}
-
-#errorExplanation ul li {
- font-size: 12px;
- list-style: square;
-}
Please sign in to comment.
Something went wrong with that request. Please try again.