class TopicsController < ApplicationController # GET /topics # GET /topics.xml def index @topics = Topic.find(:all) respond_to do |format| format.html # index.rhtml format.xml { render :xml => @topics.to_xml } end end # GET /topics/1 # GET /topics/1.xml def show @topic = Topic.find(params[:id]) respond_to do |format| format.html # show.rhtml format.xml { render :xml => @topic.to_xml } end end # GET /topics/new def new @topic = Topic.new end # GET /topics/1;edit def edit @topic = Topic.find(params[:id]) end # POST /topics # POST /topics.xml def create @topic = Topic.new(params[:topic]) @topic = prepare_for_save(@topic) respond_to do |format| if @topic.save flash[:notice] = 'Topic was successfully created.' format.html { redirect_to topic_url(@topic) } format.js { render_json({ :client_id => params[:client_id], :server_id => @topic.id }.to_json) } format.xml { head :created, :location => topic_url(@topic) } else format.html { render :action => "new" } format.js format.xml { render :xml => @topic.errors.to_xml } end end end # PUT /topics/1 # PUT /topics/1.xml def update @topic = Topic.find(params[:id]) @topic.attributes = params[:topic] @topic = prepare_for_save(@topic) respond_to do |format| if @topic.save flash[:notice] = 'Topic was successfully updated.' format.html { redirect_to topic_url(@topic) } format.js { head :ok } format.xml { head :ok } else format.html { render :action => "edit" } format.js { render_json(@topic.errors.to_json) } format.xml { render :xml => @topic.errors.to_xml } end end end # DELETE /topics/1 # DELETE /topics/1.xml def destroy @topic = Topic.find(params[:id]) @topic.destroy respond_to do |format| format.html { redirect_to topics_url } format.xml { head :ok } format.js { head :ok } end end private def prepare_for_save(topic) topic.text = strip_tags(topic.text) topic.notes = strip_tags(topic.notes) return topic end end