Class: SbPostsController
Instance Method Summary
collapse
#advertise, #cache_action?, #footer_content, #homepage_features, #plaxo, #rss_site_index, #site_index
Methods included from BaseHelper
#add_friend_link, #ajax_spinner_for, #avatar_for, #block_to_partial, #box, #city_cloud, #clippings_link, #commentable_url, #container_title, #excerpt_with_jump, #flash_class, #forum_page?, #is_current_user_and_featured?, #jumbotron, #last_active, #more_comments_links, #page_title, #paginating_links, #possesive, #profile_completeness, #render_jumbotron, #render_widgets, #rounded, #search_posts_title, #search_user_posts_path, #show_footer_content?, #tag_auto_complete_field, #time_ago_in_words, #time_ago_in_words_or_date, #topnav_tab, #truncate_words, #truncate_words_with_highlight, #widget
#get_matching_ui_locale, #get_sorted_langs_from_accept_header, #get_valid_lang_from_accept_header, #set_locale
#login_by_token, #update_last_seen_at
Instance Method Details
#create ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'app/controllers/sb_posts_controller.rb', line 55
def create
@topic = Topic.includes(:forum).where(:id => params[:topic_id].to_i, :forum_id => params[:forum_id].to_i).first
if @topic.locked?
respond_to do |format|
format.html do
flash[:notice] = :this_topic_is_locked.l
redirect_to(forum_topic_path(:forum_id => params[:forum_id], :id => params[:topic_id]))
end
end
return
end
@forum = @topic.forum
@post = @topic.sb_posts.new(sb_post_params)
@post.user = current_user if current_user
@post.author_ip = request.remote_ip
if (logged_in? || verify_recaptcha(@post)) && @post.save
respond_to do |format|
format.html do
redirect_to forum_topic_path(:forum_id => params[:forum_id], :id => params[:topic_id], :anchor => @post.dom_id, :page => params[:page] || '1')
end
format.js
end
else
flash.now[:notice] = @post.errors.full_messages.to_sentence
respond_to do |format|
format.html do
redirect_to forum_topic_path({:forum_id => params[:forum_id], :id => params[:topic_id], :anchor => 'reply-form', :page => (params[:page] || '1')}.merge({:sb_post => params[:sb_post]}))
end
format.js
end
end
end
|
#destroy ⇒ Object
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
# File 'app/controllers/sb_posts_controller.rb', line 118
def destroy
authorize @post
@post.destroy
flash[:notice] = :sb_post_was_deleted.l_with_args(:title => CGI::escapeHTML(@post.topic.title))
@post.topic.destroy and redirect_to forum_path(params[:forum_id]) if @post.topic.sb_posts_count == 1
respond_to do |format|
format.html do
redirect_to forum_topic_path(:forum_id => params[:forum_id], :id => params[:topic_id], :page => params[:page]) unless performed?
end
format.js
format.xml { head 200 }
end
end
|
#edit ⇒ Object
91
92
93
94
95
96
97
98
|
# File 'app/controllers/sb_posts_controller.rb', line 91
def edit
authorize @post
respond_to do |format|
format.html
format.js
end
end
|
#index ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
|
# File 'app/controllers/sb_posts_controller.rb', line 17
def index
conditions = []
[:user_id, :forum_id].each { |attr|
conditions << SbPost.send(:sanitize_sql, ["sb_posts.#{attr} = ?", params[attr].to_i]) if params[attr]
}
conditions = conditions.any? ? conditions.collect { |c| "(#{c})" }.join(' AND ') : nil
@posts = SbPost.with_query_options.where(conditions).page(params[:page])
@users = User.distinct.where(:id => @posts.collect(&:user_id).uniq).to_a.index_by(&:id)
end
|
#monitored ⇒ Object
38
39
40
41
|
# File 'app/controllers/sb_posts_controller.rb', line 38
def monitored
@user = User.find params[:user_id]
@posts = SbPost.with_query_options.joins('INNER JOIN monitorships ON monitorships.topic_id = topics.id').where('monitorships.user_id = ? AND sb_posts.user_id != ?', params[:user_id], @user.id).page(params[:page])
end
|
#new ⇒ Object
49
50
51
52
53
|
# File 'app/controllers/sb_posts_controller.rb', line 49
def new
if logged_in?
redirect_to forum_topic_path(:forum_id => params[:forum_id], :id => params[:topic_id], :anchor => 'reply-form', :page => params[:page] || '1') and return
end
end
|
#search ⇒ Object
29
30
31
32
33
34
35
36
|
# File 'app/controllers/sb_posts_controller.rb', line 29
def search
conditions = params[:q].blank? ? nil : SbPost.send(:sanitize_sql, ['LOWER(sb_posts.body) LIKE ?', "%#{params[:q]}%"])
@posts = SbPost.with_query_options.where(conditions).page(params[:page])
@users = User.distinct.where(:id => @posts.collect(&:user_id).uniq).to_a.index_by(&:id)
render :action => :index
end
|
#show ⇒ Object
43
44
45
46
47
|
# File 'app/controllers/sb_posts_controller.rb', line 43
def show
respond_to do |format|
format.html { redirect_to forum_topic_path(@post.forum_id, @post.topic_id) }
end
end
|
#update ⇒ Object
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
# File 'app/controllers/sb_posts_controller.rb', line 100
def update
authorize @post
@post.update_attributes(sb_post_params)
unless @post.valid?
flash[:bad_reply] = :an_error_occurred.l
end
respond_to do |format|
format.html do
redirect_to forum_topic_path(:forum_id => params[:forum_id], :id => params[:topic_id], :anchor => @post.dom_id, :page => params[:page] || '1')
end
format.js
format.xml { head 200 }
end
end
|