Merb Wiki
Home
All Pages
New Page
Editing Misc Tips
Textile Enabled
| [[Page Name]] for internal links
h2. before filter If you wish to use an action before filter but want it to be used on all the actions but one, you will need to use the exclude option: <pre><code class="ruby">before :authenticate, :exclude => :new</code></pre> You can also specify a limited list of actions that will use the filter: <pre><code class="ruby">before :authenticate, :only => [:create, :update, :destroy, :new]</code></pre> Note that Rails uses <pre><code>:except => :new</code></pre> while Merb uses <pre><code>:exclude => :new</code></pre> h3. Before Filter with Arguments You can also pass arguments to your before filter method using :with => [], like this: Your method defined elsewhere <pre><code class="ruby"> def foo(bar) bar == "baz" end </code></pre> Your Controller <pre><code class="ruby"> before :foo, :with => "baz" </code></pre> h3. Before Filter Conditions You can pass a condition which must be satisfied before your filter will run using :if and :unless : <pre><code class="ruby"> before :authenticate, :unless => :logged_in? </code></pre> The condition can be a Symbol representing a message to send or a Proc which will be called. h2. use_test dependencies If your tests require a gem that is not required in your main application code, it's best not to include the gem when running in the production environment. *use_test* accepts optional dependency arguments that will only be included in the test environment: <pre><code class="ruby">use_test :rspec, "foo_fixtures" # dependency "foo_fixtures"</code></pre> h2. how to freeze your Merb app For more info read "this blog post":http://railsontherun.com/2008/4/15/merb-tip-how-to-freeze-a-project Also of note, if you generated an app before the new style of merb-freezer, you'll want to remove the freeze code inside your Rakefile. Otherwise you'll get errors like "passing in 3 arguments for 2!" h2. how to write a Merb plugin TODO: add documentation link. To generate a new plugin: <pre><code>merb-gen plugin merb_awesome</code></pre> h2. Rails-style Initializers Sometimes you'll want to initialize a few things when your application starts. If you're a neat freak, Rails-style initializers may be of use to you. It's very simple to set this up in Merb: # Create a directory in your config folder named 'initializers' # Add the following code to the bottom of your config/init.rb file: <pre><code class="ruby"> Dir[Merb.root / 'config' / 'initializers' / '*.rb'].each do |initializer| load(initializer) end </pre></code> You're done! It's easy, and it keeps things clean. h2. Custom Rake task Add your custom rake task to: <pre><code class="ruby">Rakefile</pre></code> at the root of your Merb application h2. Auto-Reload a very-flat app Add this to your file. <pre><code class="ruby"> Merb::BootLoader.before_app_loads do Merb.push_path(:application, Merb.root, File.basename(__FILE__)) end </code></pre>
Submit
Recent Activity
Home
was updated
Home
was updated
deploying-a-merb-application-to-a-jee-container-us
was updated
deploying-a-merb-application-to-a-jee-container-us
was updated
Merb Developers available for work
was updated
deploying-a-merb-application-to-a-jee-container-us
was updated
deploying-a-merb-application-to-a-jee-container-us
was updated
deploying-a-merb-application-to-a-jee-container-us
was updated
deploying-a-merb-application-to-a-jee-container-us
was updated
Home
was updated