Class: BlogBasic::BlogPostsController

Inherits:
AppController
  • Object
show all
Defined in:
app/controllers/blog_basic/blog_posts_controller.rb

Instance Method Summary collapse

Methods inherited from AppController

#current_user, #require_user, #signed_in?

Instance Method Details

#createObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'app/controllers/blog_basic/blog_posts_controller.rb', line 64

def create
  @blog_post = BlogPost.new(params[:blog_post])

  logger.debug "blog_post controller (create) - FIXME"
  @blog_post.user_id = 1 #current_user.id
  logger.debug "value: #{params[:blog_post][:published]}"
  @blog_post.published_at = Time.now if params[:blog_post][:published].to_i > 0 && @blog_post.published_at.nil?

  respond_to do |format|
    if @blog_post.save
      flash[:notice] = 'BlogPost was successfully created.'
      format.html { redirect_to(@blog_post) }
      format.xml  { render :xml => @blog_post, :status => :created, :location => @blog_post }
    else
      format.html { render :action => "new" }
      format.xml  { render :xml => @blog_post.errors, :status => :unprocessable_entity }
    end
  end
end

#destroyObject



106
107
108
109
110
111
112
113
114
115
116
# File 'app/controllers/blog_basic/blog_posts_controller.rb', line 106

def destroy
  @blog_post = BlogPost.find(params[:id])
  #@blog_post.destroy

  flash[:notice] = 'The blog post has been deleted'

  respond_to do |format|
    format.html { redirect_to(blog_posts_url) }
    format.xml  { head :ok }
  end
end

#draftsObject



26
27
28
29
30
31
32
33
# File 'app/controllers/blog_basic/blog_posts_controller.rb', line 26

def drafts
  @blog_posts = BlogPost.drafts.paginate(:page => params[:page], :order => 'updated_at DESC')

  respond_to do |format|
    format.html # index.html.erb
    format.xml  { render :xml => @blog_posts }
  end
end

#editObject



60
61
62
# File 'app/controllers/blog_basic/blog_posts_controller.rb', line 60

def edit
  @blog_post = BlogPost.find(params[:id])
end

#indexObject



14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/blog_basic/blog_posts_controller.rb', line 14

def index
  @blog_posts = BlogPost.published.paginate(:page => params[:page], :per_page => 5)
  @index_title = BlogConf.data['blog_name'] || 'Blog'
  @ads = false

  respond_to do |format|
    format.html # index.html.erb
    format.xml  { render :xml => @blog_posts }
    format.atom 
  end
end

#newObject



51
52
53
54
55
56
57
58
# File 'app/controllers/blog_basic/blog_posts_controller.rb', line 51

def new
  @blog_post = BlogPost.new

  respond_to do |format|
    format.html # new.html.erb
    format.xml  { render :xml => @blog_post }
  end
end

#showObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/blog_basic/blog_posts_controller.rb', line 35

def show
  logger.debug "(Show)ing blog post id: " + params[:id].to_s
  @blog_post = BlogPost.find(params[:id])

  unless @blog_post.published == 1
    return unless require_admin
  end
  @blog_comment = @blog_post.blog_comments.new
  @blog_comments = @blog_post.blog_comments.paginate(:page => params[:page], :order => 'created_at DESC')
  @ads = true
  respond_to do |format|
    format.html # show.html.erb
    format.xml  { render :xml => @blog_post }
  end
end

#updateObject



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'app/controllers/blog_basic/blog_posts_controller.rb', line 84

def update
  @blog_post = BlogPost.find(params[:id])

  blog_log = BlogContent.create()
  blog_log.title = @blog_post.title
  blog_log.content = @blog_post.body
  blog_log.blog_post_id = params[:id]
  blog_log.save

  respond_to do |format|
    @blog_post.published_at = Time.now if params[:blog_post][:published].to_i > 0 && @blog_post.published_at.nil?
    if @blog_post.update_attributes(params[:blog_post])
      flash[:notice] = 'BlogPost was successfully updated.'
      format.html { redirect_to(@blog_post) }
      format.xml  { head :ok }
    else
      format.html { render :action => "edit" }
      format.xml  { render :xml => @blog_post.errors, :status => :unprocessable_entity }
    end
  end
end