Sha256: 1792336244a75d4167fae59ca0fec3afedc251edb45fe90307cd2ab9e45b4bfb
Contents?: true
Size: 1.9 KB
Versions: 3
Compression:
Stored size: 1.9 KB
Contents
module Formol class PostsController < ApplicationController include Controllers::Nested::HasParentTopic respond_to :html def show formol_authorize!(current_formol_user, :read_topic) post #respond_with location doesn't work here :/ respond_with(post) do |format| format.html { redirect_to paginated_forum_topic_post_path(post.topic.forum, post.topic, post) } end end def new formol_authorize!(current_formol_user, :create_post, topic) post(:quote_id => params[:quote], :user => current_formol_user) end def create formol_authorize!(current_formol_user, :create_post, topic) post(:user => current_formol_user) if post.save #post.topic(true) needed to handle counter increment respond_with(post, :status => :created, :location => last_page_forum_topic_path(topic.forum, post.topic(true), post)) else respond_with(post, :status => :unprocessable_entity) do |format| format.html { render :new } end end end def edit formol_authorize!(current_formol_user, :edit_post, post) post end def update formol_authorize!(current_formol_user, :edit_post, post) if post.update_attributes(params[:post]) respond_with(post, :location => paginated_forum_topic_post_path(topic.forum, topic, post)) else respond_with(post) do |format| format.html { render :edit } end end end def destroy formol_authorize!(current_formol_user, :destroy_post) post.destroy respond_with(post, :location => [topic.forum, topic]) end protected def post(attrs = {}) @post ||= (params[:id].present? ? topic.posts.find(params[:id]) : topic.posts.new(attrs.merge(params[:post] || {}))) end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
formol-0.0.6 | app/controllers/formol/posts_controller.rb |
formol-0.0.5 | app/controllers/formol/posts_controller.rb |
formol-0.0.4 | app/controllers/formol/posts_controller.rb |