Class: Admin::Whatson::PostsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/admin/whatson/posts_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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
# File 'app/controllers/admin/whatson/posts_controller.rb', line 36

def create
  # if the position field exists, set this object as last object, given the conditions of this class.
  if WhatsonPost.column_names.include?("position")
    params[:whatson_post].merge!({
      :position => ((WhatsonPost.maximum(:position, :conditions => "")||-1) + 1)
    })
  end
    
  if WhatsonPost.column_names.include?("user_id")
    params[:whatson_post].merge!({
      :user_id => current_user.id
    })
  end

  if (@whatson_post = WhatsonPost.create(params[:whatson_post])).valid?
    (request.xhr? ? flash.now : flash).notice = t(
      'refinery.crudify.created',
      :what => "'#{@whatson_post.title}'"
    )

    unless from_dialog?
      unless params[:continue_editing] =~ /true|on|1/
        redirect_back_or_default(admin_whatson_posts_url)
      else
        unless request.xhr?
          redirect_to :back
        else
          render :partial => "/shared/message"
        end
      end
    else
      render :text => "<script>parent.window.location = '#{admin_whatson_posts_url}';</script>"
    end
  else
    unless request.xhr?
      render :action => 'new'
    else
      render :partial => "/shared/admin/error_messages",
             :locals => {
               :object => @whatson_post,
               :include_object_name => true
             }
    end
  end
end

#tagsObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/admin/whatson/posts_controller.rb', line 17

def tags
  op =  case ActiveRecord::Base.connection.adapter_name.downcase
        when 'postgresql'
          '~*'
        else
          'LIKE'
        end
  wildcard =  case ActiveRecord::Base.connection.adapter_name.downcase
              when 'postgresql'
                '.*'
              else
                '%'
              end
  @tags = WhatsonPost.tag_counts_on(:tags).where(
      ["tags.name #{op} ?", "#{wildcard}#{params[:term].to_s.downcase}#{wildcard}"]
    ).map { |tag| {:id => tag.id, :value => tag.name}}
  render :json => @tags.flatten
end

#uncategorizedObject



10
11
12
13
14
15
# File 'app/controllers/admin/whatson/posts_controller.rb', line 10

def uncategorized
  @whatson_posts = WhatsonPost.uncategorized.paginate({
    :page => params[:page],
    :per_page => WhatsonPost.per_page
  })
end