public
Created

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

  • Download Gist
_form.html.erb
HTML+ERB
1 2 3 4 5 6
<%= f.input :text %>
<%= f.input :tag_list %>
 
<% if params[:reply_to_id] %>
<%= f.hidden_field :reply_to_id, :value => params[:reply_to_id] %>
<% end %>
new.html.erb
HTML+ERB
1 2 3
<h2><%= t("forem.topic.new") %></h2>
 
<%= render "form" %>
post_decorator.rb
Ruby
1 2 3 4
Forem::Post.class_eval do
acts_as_taggable_on :tags
attr_accessible :tag_list
end
topics_controller.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.