Class: Almanac::PostsController
Instance Method Summary
collapse
#set_blog, #set_current_author
Instance Method Details
#create ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'app/controllers/almanac/posts_controller.rb', line 73
def create
@post = Post.new(params[:post])
@post.blog = Almanac::Blog.first
@post.author_id = current_user.id
respond_with(@post) do |format|
if @post.save
format.html { redirect_to :root, :notice => 'Post was successfully created.' }
else
@post.id = 0
format.html { render :action => "new", :alert => 'Something went wrong, try again.' }
end
end
end
|
#destroy ⇒ Object
106
107
108
109
110
111
112
113
114
115
116
|
# File 'app/controllers/almanac/posts_controller.rb', line 106
def destroy
post_id = @post.id
respond_to do |format|
if @post.destroy
format.html { redirect_to :root, :notice => 'Post was successfully deleted.' }
format.js { render :nothing => true }
else
format.html { redirect_to post_path(@post), :alert => 'Something went wrong, try again.' }
end
end
end
|
#draft ⇒ Object
55
56
57
58
59
60
61
|
# File 'app/controllers/almanac/posts_controller.rb', line 55
def draft
@post = Post.find(params[:id])
respond_with(@post) do |format|
format.html
end
end
|
#edit ⇒ Object
88
89
90
91
92
|
# File 'app/controllers/almanac/posts_controller.rb', line 88
def edit
respond_to do |format|
format.html
end
end
|
#index ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'app/controllers/almanac/posts_controller.rb', line 11
def index
@posts = (@blog.nil?) ? [] : Post.recent(params)
@drafts = (@blog.nil? or current_user.nil?) ? [] : Post.drafts(params)
respond_with(@posts) do |format|
if @blog.nil?
unless current_user.nil?
format.html { redirect_to new_blog_path }
end
else
format.html
format. { render :layout => false }
end
end
end
|
#new ⇒ Object
63
64
65
66
67
68
69
70
71
|
# File 'app/controllers/almanac/posts_controller.rb', line 63
def new
@post = Post.new
@post.id = 0
@images = @post.images
respond_with(@post) do |format|
format.html
end
end
|
#show ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
|
# File 'app/controllers/almanac/posts_controller.rb', line 43
def show
@post = Post.find_by_slug(params[:slug])
if @post.nil? and not params[:slug].empty?
redirect_to edit_post_path(params[:slug]), :notice => "Your post has to have a slug."
return
end
respond_with(@post) do |format|
format.html
end
end
|
#tag ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'app/controllers/almanac/posts_controller.rb', line 27
def tag
@posts = (@blog.nil?) ? [] : Post.tagged(params)
@tag = params[:tag_name]
respond_with(@posts) do |format|
if @blog.nil?
unless current_user.nil?
format.html { redirect_to new_path }
end
else
format.html
format. { render :layout => false }
end
end
end
|
#update ⇒ Object
94
95
96
97
98
99
100
101
102
103
104
|
# File 'app/controllers/almanac/posts_controller.rb', line 94
def update
@post.blog = Almanac::Blog.first
respond_with(@post) do |format|
if @post.update_attributes(params[:post])
format.html { redirect_to :root, :notice => 'Post was successfully updated.' }
else
format.html { render :action => "edit" }
end
end
end
|