Changeset 156

Show
Ignore:
Timestamp:
01/16/07 20:51:57 (2 years ago)
Author:
e.@brainspl.at
Message:

add sleeper loop to keep db connection a live

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/README

    r135 r156  
    1313json or fjson 
    1414mime-types 
     15archive-tar-minitar 
     16rspec 
    1517 
    1618Install these gems first then you can build the merb gem from svn trunk like so: 
    17 $ sudo gem install mongrel erubis json mime-types --include-dependencies 
    18 $ svn co http://svn.devjavu.com/merb 
     19$ sudo gem install mongrel erubis json mime-types archive-tar-minitar rspec --include-dependencies 
     20$ svn co http://svn.devjavu.com/merb/trunk merb 
    1921$ cd merb 
    20 $ sudo rake install 
    21  
    22 **Important** 
    23 The new default filename extensions for templates are as follows 
    24 html ->  .herb 
    25 js   ->  .jerb 
    26 xml  ->  .xerb 
    27  
    28 You can change the extensions to anything you want in your config file in 
    29 yourapp/dist/conf/merb.yml. See the default settings in the sample app. 
    30  
    31 First you need to install the dependencies. Merb requires the following gems 
    32  
    33 erubis 
    34  
    35 json 
    36  
    37 fjson # will be used if present. requires C extension. 
    38  
    39 # fastthread will be used if present and is reccommended. 
    40 sudo gem install fastthread --source=http://mongrel.rubyforge.org/releases/ 
    41  
    42 If you have checked out merb trunk from svn you will want to build and install 
    43 the gem to use merb. Run this command from the root of the merb svn checkout 
    44 to do that: 
    45  
    46 $ sudo rake install 
    47  
    48  
    49 If you installed merb from gems then unpack the gem and grab the sample app 
    50 $ gem unpack merb 
    51  
    52 now with either the svn or the unpacked gem you can try out the sample app. 
    53  
    54 $ cd merb* 
    55 $ cd examples/sample_app 
    56  
    57 $ merb 
    58  
    59 To use the upload example at /files you will need to add a cli flag 
    60 so use the -f flag to load a config file for merb_upload_progress 
    61 $ merb -f dist/conf/mup.conf 
    62  
    63 then the sample app will be running on port 4000 in the foreground.  
    64 you can go to a few urls: 
    65 http://localhost:4000/files/start 
    66  
    67 http://localhost:4000/foo/123/baz/12234345 
     22$ rake install 
     23 
     24To generate a new merb app after the gem is installed: 
     25$ merb -g myapp 
     26 
    6827 
    6928**FEATURES**  
     
    11271layouts. It will look for a layout named after your controller class first and 
    11372then fall back to application.herb if no layout exists named after your controller. 
    114 You can use render_no_layout or do layout :none right before you render 
     73You can use render_no_layout or do render :layout => :none 
    11574 
    11675 
     
    12382end 
    12483 
    125 <html>  
    126   <head>  
    127     <title>Hello, <%= @name %></title>  
    128   </head>  
    129   <body>  
    130 <%= @layout_content %> 
    131   </body>  
    132 </html> 
    133  
    134  
    135 <h1><%= params.inspect %></h1>  
    136 <h1><%= cookies.inspect %></h1> 
    137 <% 5.times do %> 
    138   <h1>Hello, <%= @name %>!</h1>  
    139 <% end %> 
    140  
    14184You can also render partials like so: 
    14285<%= partial(:comments) %> 
    143  
    14486This assumes a _comments.rhtml file in the same view dir as the current  
    14587controller/view 
     88 
     89Partials compile the template ands returns a string. So you can also call 
     90them and assign them to a var if you want: 
     91 
     92def someaction 
     93  @one = partial(:one) 
     94  @two = partial(:two) 
     95end 
     96 
     97partials can also render views from other controllers by specifying the path 
     98 
     99partial('/shared/foo') 
     100 
    146101 
    147102Merb also allows for returning javascript instead of html for ajax actions 
     
    167122 
    168123 
    169 *Controllers also now have before filters* 
     124*Controllers have powerful before and after filters* 
    170125 
    171126Use the before method in your controllers. before accepts either a symbol  
    172127or a Proc/lambda object. If you give it a symbol it will call a method with 
    173128the same name as the symbol. If you give it a proc that takes one argument  
    174 it will call the proc with the current controller as that argument. 
     129it will call the proc with the current controller as that argument. You can  
     130use :only and :exclude as options to your filters to exclude or include actionsfrom certain filters. :only and :exclude take :symbols or [:sym, :sam] 
     131array of symbols. 
    175132 
    176133class Foo < Merb::Controller 
    177134  
    178   before :setup_user 
    179   before lambda {|c| c.headers['X-Foo] = 'bar' } 
     135  before :setup_user, :only => :foo 
     136  before lambda {|c| c.headers['X-Foo] = 'bar' }, :exclude => [:foo, :baz] 
    180137 
    181138  def setup_user 
     
    183140  end 
    184141 
     142  def foo 
     143    # blah 
     144  end 
     145 
    185146  def regular_action 
    186147    # blah 
     
    189150end 
    190151 
    191 Sessions are available when you start merb with the sql_session set to true or the memory_session set to true. See sample app for 
    192 migration too add session table. 
     152To stop the before filter chain you use throw :halt with a few options: 
     153 
     154# halts the filter chain and calls filters_halted which you can override  
     155# in your controller to specialize it. 
     156 
     157throw :halt 
     158 
     159# halts the filters and calls the method named after the symbol: 
     160 
     161throw :halt, :other_action 
     162 
     163# halts the filter chain and returns the result of the Proc being called 
     164 
     165throw :halt, Proc.new{ |c| c.redirect "/foo" } 
     166 
     167# halts the chain and returns whatever is in the string 
     168 
     169throw :halt, "<h1>You don't have permissions IDIOT!</h1>" 
     170 
     171or even render templates: 
     172 
     173throw :halt, render 'foo' 
     174throw :halt, partial 'foo' 
     175 
     176After filters only accept a Proc and call that proc with the controller: 
     177 
     178after Proc.new {|c| Tidy.new(c.body) }, :only => :index 
     179 
     180Sessions are available when you start merb with the sql_session set to true or the memory_session set to true. See generated app for migration too add session table. 
     181 
     182Helpers: dist/app/helpers/global_helper.rb will be available to all of your views. Helpers named afdter your controller plus _helper.rb will be included in the views for that controller only. 
    193183 
    194184 
     
    216206*File uploads*  
    217207This is one of the things that Merb was written for. Rails doesn't allow  
    218 multiple concurrent file uploads at once without blocking an entire rails backend  
    219 for each file upload. Merb allows multiple file uploads at once. Start the server  
    220 and browse to http://localhost:4000/files/start  and you will get a file upload  
    221 form. This uses the mongrel_upload_progress gem so that must be installed first. 
    222 There is a very simple upload controller example that handles this upload with a  
     208multiple concurrent file uploads at once without blocking an entire rails backend for each file upload. Merb allows multiple file uploads at once. 
    223209progress bar. When a file is uploaded with Merb, it gets put in a Tempfile. So  
    224210you just want to copy it to the right place on the filesystem. 
     
    243229will put the dist dir into another empty MERB_ROOT on the production server. 
    244230 
    245 rm -rf project 
    246 mkdir -p project/{log,plugins,script,test/{specs,unit},dist/{conf,lib,plugins,schema/migrations,public/{javascripts,images,stylesheets},app/{controllers,helpers,models,views/layouts}}} 
    247 mate project 
    248  
    249 app_skeleton 
     231merb_app: 
    250232  Rakefile 
    251233  README 
    252234  scripts 
    253235  test 
    254     test_helper.rb 
    255     fixtures 
    256236    spec 
    257237    unit 
  • trunk/lib/merb.rb

    r125 r156  
    1111  require 'json' 
    1212end 
     13 
    1314 
    1415module Merb 
     
    9495    require "merb/session/merb_ar_session" 
    9596    include ::Merb::SessionMixin 
     97    t = Thread.new{ loop{ sleep(60*60); ActiveRecord::Base.verify_active_connections! } }.priority = -10 
    9698  end 
    9799