Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class TopicsController < ApplicationController
- before_filter :set_topic, :only => [:show, :edit, :update, :destroy]
- def index
- @topics = current_user.topics
- end
- def show
- @topic.update_topic_hits
- @topic_hits = @topic.topic_hits.paginate(:page => params[:page] || 1, :per_page => params[:per_page])
- end
- def new
- @topic = Topic.new
- end
- def edit
- end
- def create
- @topic = Topic.new(params[:topic])
- @topic.user = current_user
- if @topic.save
- flash[:notice] = 'News Monitor was successfully created.'
- redirect_to @topic
- else
- render :action => "new"
- end
- end
- def update
- if @topic.update_attributes(params[:topic])
- flash[:notice] = 'News Monitor was successfully updated.'
- redirect_to @topic
- else
- render :action => "edit"
- end
- end
- def destroy
- @topic = Topic.find(params[:id])
- @topic.destroy
- redirect_to(topics_url)
- end
- protected
- def set_topic
- @topic = Topic.find(params[:id])
- access_denied unless @topic.user == current_user
- end
- end
Add Comment
Please, Sign In to add comment