Skip to content
This repository has been archived by the owner on May 18, 2018. It is now read-only.

Commit

Permalink
Updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
dim committed Jul 1, 2011
1 parent 0063ad6 commit 70e1fac
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,26 @@ What about associations?
Post.constrain(params[:where])
# => SELECT posts.* FROM posts LEFT OUTER JOIN authors ON authors.id = posts.author_id WHERE authors.name LIKE '%tom%'

Integration with controllers, views & filter forms:

# In app/models/post.rb
class Post < ActiveRecord::Base
constrainable do
fields :author_id
end
end

# In app/controllers/posts_controller.rb
class PostsController < ApplicationController
respond_to :html

def index
@filters = Post.constrainable.fliter(params[:where])
@posts = Post.constrain(@filters)
respond_with @posts
end
end

# In app/views/posts/index.html.haml
= form_for @filters, :as => :where do
= f.collection_select :"author_id[eq]", Author.order('name'), :id, :name

0 comments on commit 70e1fac

Please sign in to comment.