Browse the Ruby on Rails Community.

You are here: Browse Railsplugins Params Finder

Params Finder

Provides dynamic methods for initialize models in your URL parameters.

Example

class PeopleController < ApplicationController
  before_filter :find_person, :only => %w( show edit update destroy )
end
def index
  @people = Person.find(:all)
end
def show
end
def new
  @person = Person.new
end
def edit
end
def create
  @person = Person.new(params[:person])
end
if @person.save
  flash[:notice] = 'Person was successfully created.'
  redirect_to(@person)
else
  render :action => "new" 
end
def update
  if @person.update_attributes(params[:person])
    flash[:notice] = 'Person was successfully updated.'
    redirect_to(@person)
  else
    render :action => "edit" 
  end
end
def destroy
  @person.destroy
  redirect_to(people_url)
end
  1. This method is provided magically
  2. protected
  3. def find_person
  4. @person = Person.find(params[:id])
  5. end

Copyright© 2007 Joshua Peek, released under the MIT license