Files
danbooru/app/controllers/notes_controller.rb
2011-05-16 09:27:06 -04:00

59 lines
1.2 KiB
Ruby

class NotesController < ApplicationController
respond_to :html, :xml, :json
before_filter :member_only, :except => [:index, :show]
def index
if params[:group_by] == "post"
index_by_post
else
index_by_note
end
end
def show
@note = Note.find(params[:id])
respond_with(@note)
end
def create
@note = Note.create(params[:note])
respond_with(@note)
end
def update
@note = Note.find(params[:id])
@note.update_attributes(params[:note])
respond_with(@note)
end
def destroy
@note = Note.find(params[:id])
@note.destroy
respond_with(@note)
end
def revert
@note = Note.find(params[:id])
@version = NoteVersion.find(params[:version_id])
@note.revert_to!(@version)
respond_with(@note)
end
private
def index_by_post
@posts = Post.tag_match(params[:tags]).noted_before(params[:before_date] || Time.now).limit(8)
respond_with(@posts) do |format|
format.html {render :action => "index_by_post"}
end
end
def index_by_note
@search = Note.search(params[:search])
@notes = @search.paginate(:page => params[:page])
respond_with(@notes) do |format|
format.html {render :action => "index_by_note"}
end
end
end