Sha256: a2d54983b84d0bd111e723ba8994c06ae5f2bd0c7365108d75e20e4c9cba50c0
Contents?: true
Size: 1.39 KB
Versions: 2
Compression:
Stored size: 1.39 KB
Contents
require_dependency "mongoid_forums/application_controller" module MongoidForums class ForumsController < ApplicationController def index @categories = Category.all.order_by([:order, :asc]) 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]) @topic = Topic.new @topic.forum = @forum.id end def create @forum = Forum.find(params[:forum_id]) @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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
mongoid-forums-0.0.2 | app/controllers/mongoid_forums/forums_controller.rb |
mongoid-forums-0.0.1 | app/controllers/mongoid_forums/forums_controller.rb |