Browse the Ruby on Rails Community.

You are here: Browse Railsplugins Needy Controllers

Needy Controllers

= NeedyControllers

Needy Controllers is a way to DRY up commonly used tasks from both controllers and views to save time and effort. It consists of a single call with a number of options.

Description

With needy controllers, you can include stylesheets, javascripts, and records in your controllers and views with a much greater deal of specificity and automation than hand-coding.

Installation

script/plugin install http://svn.intridea.com/svn/public/needy_controllers

Usage = Styles and Scripts

To use Needy Controllers for styles and scripts, you simply call needs inside your controller like so:

class MyController < ApplicationController needs :styles => :standard needs :styles => :show, :only => :show needs :scripts => :behave, :except => :show end

def index
  # this action will have access to the 'standard.css' stylesheet
end
def show
  # this action will have access to the 'show.css' stylesheet
  # in addition to 'standard.css'
  # but will not have access to 'behave.js'
end

Now that you have created your behavior and style chains, you need to include them in the view. Luckily, this is exceedingly easy! Just include :needs in your include and link tags like so:

<%= stylesheet_link_tag ‘something’, :needs %> <%= javascript_include_tag ‘prototype’, :needs, ‘effects’ %>

=== Model Fetching

To use Needy Controllers for fetching records, you use it similarly, and it sets the instance variable:

class MyController < ApplicationController # here’s a standard problem needs :record => :user, :except => :index end

def index
  # no @user here
end
def show
  # you can access @user in your view for this action
end

You can use :as to rename the instance variable and :from for the source id (default is params[:id]):

needs :record => :user, :as => :person, :from => params[:user_id]

== Other

Created by Michael Bleigh (michael@intridea.com) of Intridea (http://www.intridea.com)

Comments, bugs, and patches go to http://trac.intridea.com/trac/public

NOTE: This description has been extracted from the Plugin README and so the formatting may need updating to make browser friendly

Users


See all details


Membership

+ Join this railsplugin

Record Maintainer

'None'