Skip to content

Instantly share code, notes, and snippets.

@petrblaho
Created December 16, 2009 15:34
Show Gist options
  • Save petrblaho/257917 to your computer and use it in GitHub Desktop.
Save petrblaho/257917 to your computer and use it in GitHub Desktop.
class Comment < ActiveRecord::Base
belongs_to :post
end
class CommentsController < ApplicationController::Base
def index
@post = Post.find(params[:post_id])
if @post
@search = @post.comments.search(params[:search])
else
@search = Comment.search(params[:search])
end
@comments = @search.all
end
end
<table>
<tr>
<%= order @search, :by => :title, :as => 'Title' %>
</tr>
...
</table>
class Post < ActiveRecord::Base
has_many :comments
end
ActionController::Routing::Routes.draw do |map|
map.resources :comments # for overview of all comments
map.resources :post, :has_many => :comments
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment