Class: CategoriesController

Inherits:
BaseController show all
Defined in:
app/controllers/categories_controller.rb

Instance Method Summary collapse

Methods inherited from BaseController

#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, #tiny_mce_init_if_needed, #tiny_mce_js, #topnav_tab, #truncate_words, #truncate_words_with_highlight, #widget

Methods included from LocalizedApplication

#get_matching_ui_locale, #get_sorted_langs_from_accept_header, #get_valid_lang_from_accept_header, #set_locale

Methods included from AuthenticatedSystem

#login_by_token, #update_last_seen_at

Instance Method Details

#createObject

POST /categories POST /categories.xml


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'app/controllers/categories_controller.rb', line 59

def create
  @category = Category.new(category_params)

  respond_to do |format|
    if @category.save
      flash[:notice] = :category_was_successfully_created.l

      format.html { redirect_to category_url(@category) }
      format.xml do
        headers["Location"] = category_url(@category)
        render :nothing => true, :status => "201 Created"
      end
    else
      format.html { render :action => "new" }
      format.xml  { render :xml => @category.errors.to_xml }
    end
  end
end

#destroyObject

DELETE /categories/1 DELETE /categories/1.xml


96
97
98
99
100
101
102
103
104
# File 'app/controllers/categories_controller.rb', line 96

def destroy
  @category = Category.find(params[:id])
  @category.destroy

  respond_to do |format|
    format.html { redirect_to categories_url   }
    format.xml  { render :nothing => true }
  end
end

#editObject

GET /categories/1;edit


53
54
55
# File 'app/controllers/categories_controller.rb', line 53

def edit
  @category = Category.find(params[:id])
end

#indexObject

GET /categories GET /categories.xml


9
10
11
12
13
14
15
16
# File 'app/controllers/categories_controller.rb', line 9

def index
  @categories = Category.all

  respond_to do |format|
    format.html # index.rhtml
    format.xml  { render :xml => @categories.to_xml }
  end
end

#newObject

GET /categories/new


48
49
50
# File 'app/controllers/categories_controller.rb', line 48

def new
  @category = Category.new
end

#showObject

GET /categories/1 GET /categories/1.xml


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
# File 'app/controllers/categories_controller.rb', line 20

def show
  @category = Category.find(params[:id])

  order = (params[:popular] ? "view_count #{params[:popular].eql?('DESC') ? 'DESC' : 'ASC'}": "published_at DESC")

  @posts = Post.includes(:tags).where('category_id = ?', @category.id).order(order).page(params[:page])

  @popular_posts = @category.posts.order("view_count DESC").limit(10)
  @popular_polls = Poll.find_popular_in_category(@category)

  @rss_title = "#{configatron.community_name}: #{@category.name} "+:posts.l
  @rss_url = category_path(@category, :format => :rss)

  @active_users = User.includes(:posts).where("posts.category_id = ? AND posts.published_at > ?", @category.id, 14.days.ago).references(:posts).limit(5).order("users.view_count DESC").to_a

  respond_to do |format|
    format.html # show.rhtml
    format.rss {
      render_rss_feed_for(@posts, {:feed => {:title => "#{configatron.community_name}: #{@category.name} "+:posts.l, :link => category_url(@category)},
        :item => {:title => :title,
                  :link =>  Proc.new {|post| user_post_url(post.user, post)},
                  :description => :post,
                  :pub_date => :published_at} })
    }
  end
end

#show_tipsObject


106
107
108
109
110
111
# File 'app/controllers/categories_controller.rb', line 106

def show_tips
  @category = Category.find(params[:id] )
  render :partial => "/categories/tips", :locals => {:category => @category}
rescue ActiveRecord::RecordNotFound
  render :partial => "/categories/tips", :locals => {:category => nil}
end

#updateObject

patch /categories/1 patch /categories/1.xml


80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'app/controllers/categories_controller.rb', line 80

def update
  @category = Category.find(params[:id])

  respond_to do |format|
    if @category.update_attributes(category_params)
      format.html { redirect_to category_url(@category) }
      format.xml  { render :nothing => true }
    else
      format.html { render :action => "edit" }
      format.xml  { render :xml => @category.errors.to_xml }
    end
  end
end