Sha256: 735e07830c8506d27da67b23cd4ba2bbe72f9461e4e02f2607707dfb43c12963
Contents?: true
Size: 1.72 KB
Versions: 4
Compression:
Stored size: 1.72 KB
Contents
require_dependency "mongoid_forums/application_controller" module MongoidForums class ForumsController < ApplicationController load_and_authorize_resource :class => 'MongoidForums::Forum', :only => :show before_filter :authenticate_mongoid_forums_user, :only => [:create, :new] def index @categories = Category.asc(:position) end def show @forum = Forum.find(params[:id]) register_view @topics = @forum.topics @topics = @topics.by_pinned_or_most_recent_post.page(params[:page]).per(MongoidForums.per_page) end # Note: This is not an action to make a new Forum! # it is to create a new TOPIC within a forum def new @forum = Forum.find(params[:forum_id]) authorize! :create_topic, @forum @topic = Topic.new @topic.forum = @forum.id end # Note: This is not an action to make a new Forum! # it is to create a new TOPIC within a forum def create @forum = Forum.find(params[:forum_id]) authorize! :create_topic, @forum @topic = Topic.new @topic.name = topic_params[:name] @topic.user = mongoid_forums_user.id @topic.forum = @forum.id @post = Post.new @post.user = mongoid_forums_user.id @post.text = topic_params[:posts][:text] @topic.posts << @post if @topic.save && @topic.posts.first.save flash[:notice] = "Topic created successfully" redirect_to @topic else flash.now.alert = "Topic could not be created" render :action => "new" end end private def register_view @forum.register_view_by(mongoid_forums_user) end def topic_params params.require(:topic).permit(:name, :posts => [:text]) end end end
Version data entries
4 entries across 4 versions & 1 rubygems