Skip to content

Instantly share code, notes, and snippets.

@kunalchaudhari
Created July 11, 2012 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kunalchaudhari/3090920 to your computer and use it in GitHub Desktop.
Save kunalchaudhari/3090920 to your computer and use it in GitHub Desktop.
i am using forem gem and i have post model decorator. i would like to make the post taggable and using the act-as-taggable-on gem. but it giving me error that tag_list method is undefine. when i do post = Forem.Post.new and post.tag_list = 'tag1 tag2' in
<%= f.input :text %>
<%= f.input :tag_list %>
<% if params[:reply_to_id] %>
<%= f.hidden_field :reply_to_id, :value => params[:reply_to_id] %>
<% end %>
<h2><%= t("forem.topic.new") %></h2>
<%= render "form" %>
Forem::Post.class_eval do
acts_as_taggable_on :tags
attr_accessible :tag_list
end
module Forem
class TopicsController < Forem::ApplicationController
helper 'forem/posts'
before_filter :authenticate_forem_user, :except => [:show]
before_filter :find_forum
before_filter :block_spammers, :only => [:new, :create]
def new
authorize! :create_topic, @forum
@topic = @forum.topics.build
@topic.posts.build
end
def create
authorize! :create_topic, @forum
@topic = @forum.topics.build(params[:topic])
@topic.user = forem_user
if @topic.save
flash[:notice] = t("forem.topic.created")
redirect_to [@forum, @topic]
else
flash.now.alert = t("forem.topic.not_created")
render :action => "new"
end
end
private
def find_forum
@forum = Forem::Forum.find(params[:forum_id])
authorize! :read, @forum
end
def find_topic
begin
scope = forem_admin_or_moderator?(@forum) ? @forum.topics : @forum.topics.visible.approved_or_pending_review_for(forem_user)
@topic = scope.find(params[:id])
authorize! :read, @topic
rescue ActiveRecord::RecordNotFound
flash.alert = t("forem.topic.not_found")
redirect_to @forum and return
end
end
def register_view
@topic.register_view_by(forem_user)
end
def block_spammers
if forem_user.forem_state == "spam"
flash[:alert] = t('forem.general.flagged_for_spam') + ' ' + t('forem.general.cannot_create_topic')
redirect_to :back
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment