Class: DmForum::ForumTopicsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- DmForum::ForumTopicsController
- Includes:
- PermittedParams
- Defined in:
- app/controllers/dm_forum/forum_topics_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
——————————————————————————.
-
#destroy ⇒ Object
——————————————————————————.
-
#edit ⇒ Object
——————————————————————————.
-
#index ⇒ Object
——————————————————————————.
-
#new ⇒ Object
——————————————————————————.
-
#show ⇒ Object
——————————————————————————.
-
#toggle_follow ⇒ Object
——————————————————————————.
-
#update ⇒ Object
——————————————————————————.
Methods included from PermittedParams
#forum_category_params, #forum_comment_params, #forum_params, #forum_site_params, #forum_topic_params
Methods included from ForumHelper
#edited_on_tag, #feed_icon_tag, #forum_comment_user_state, #forum_crumbs, #forum_topic_icon, #last_active, #modify_history, #recent_forum_activity, #recent_topic_activity, #topic_title_link, #voice_count
Instance Method Details
#create ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/controllers/dm_forum/forum_topics_controller.rb', line 37 def create params[:forum_topic].delete(:forum_id) @forum_topic = @forum.forum_topics.new(forum_topic_params) @forum_topic.user = current_user if @forum_topic.save current_user.following.follow(@forum_topic) redirect_to forum_forum_topic_path(@forum, @forum_topic), notice: 'Topic was successfully created.' else render :action => :new end end |
#destroy ⇒ Object
69 70 71 72 |
# File 'app/controllers/dm_forum/forum_topics_controller.rb', line 69 def destroy @forum_topic.destroy if is_admin? redirect_to @forum end |
#edit ⇒ Object
50 51 |
# File 'app/controllers/dm_forum/forum_topics_controller.rb', line 50 def edit end |
#index ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'app/controllers/dm_forum/forum_topics_controller.rb', line 12 def index respond_to do |format| format.html { redirect_to forum_path(@forum) } format.xml do @forum_topics = find_forum.topics.paginate(:page => page_number) render :xml => @forum_topics end end end |
#new ⇒ Object
32 33 34 |
# File 'app/controllers/dm_forum/forum_topics_controller.rb', line 32 def new @forum_topic = @forum.forum_topics.new end |
#show ⇒ Object
23 24 25 26 27 28 29 |
# File 'app/controllers/dm_forum/forum_topics_controller.rb', line 23 def show (session[:forum_topics] ||= {})[@forum_topic.id] = Time.now.utc if user_signed_in? @forum_topic.hit! unless user_signed_in? && @forum_topic.user_id == current_user.id @forum_comments = @forum_topic.forum_comments.paginate :page => page_number @forum_comment = ForumComment.new @following = user_signed_in? && @forum_topic.followed_by?(current_user.following) end |
#toggle_follow ⇒ Object
75 76 77 78 79 |
# File 'app/controllers/dm_forum/forum_topics_controller.rb', line 75 def toggle_follow @forum_topic = @forum.forum_topics.find(params[:forum_topic_id]) @following = current_user.following.following?(@forum_topic) @following ? current_user.following.stop_following(@forum_topic) : current_user.following.follow(@forum_topic) end |
#update ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/controllers/dm_forum/forum_topics_controller.rb', line 54 def update #current_user.revise @topic, params[:topic] attributes = forum_topic_params @forum_topic.title = attributes[:title] if attributes.key?(:title) @forum_topic.sticky, @forum_topic.locked, @forum_topic.forum_id = attributes[:sticky], attributes[:locked], attributes[:forum_id] if can?(:moderate, @forum_topic.forum) @forum_topic.save if @forum_topic.errors.empty? flash[:notice] = 'Topic was successfully updated.' redirect_to(forum_forum_topic_path(Forum.find(@forum_topic.forum_id), @forum_topic)) else render :action => "edit" end end |