Class: Blog::BlogsController
Instance Method Summary
collapse
#can_manage_blogs, #can_manage_contexts
#allowable_html, #construct_blog_path, #posted_by_on
Instance Method Details
#create ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'app/controllers/blog/blogs_controller.rb', line 32
def create
params[:blog].merge!(:user_id => current_user.id)
@blog = Blog.new(params[:blog])
if @blog.save
redirect_to(construct_blog_path(@blog, :show), :notice => "#{@blog.title} was successfully created.")
else
@context_options = Context.selections
@context = @blog.context
render :action => :new
end
end
|
#destroy ⇒ Object
73
74
75
76
77
78
79
80
81
|
# File 'app/controllers/blog/blogs_controller.rb', line 73
def destroy
title = @blog.title
@blog.destroy
respond_to do |format|
format.html { redirect_to construct_blog_path(@blog, :index), :notice => "'#{title}' was successfully removed" }
format.json { head :ok }
end
end
|
#index ⇒ Object
10
11
12
13
14
15
16
17
|
# File 'app/controllers/blog/blogs_controller.rb', line 10
def index
if @context
@blogs = Blog.where("context_id = ?", @context.id).limit(10).order('created_at desc').paginate(:page => params[:page]).per_page(10)
@archive = Blog.where("context_id = ? and id not in (?)", @context, @blogs.collect{|b| b.id}).limit(10).order('created_at desc')
else
@blogs = Blog.all
end
end
|
#new ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'app/controllers/blog/blogs_controller.rb', line 19
def new
@context ||= Context.first
@context_options = Context.selections
@blog = Blog.new(:context => @context, :photo => Photo.new)
respond_to do |format|
format.html { render }
format.xml { render :xml => @blog }
end
end
|
#show ⇒ Object
47
48
49
50
51
52
53
54
55
|
# File 'app/controllers/blog/blogs_controller.rb', line 47
def show
raise ActiveRecord::RecordNotFound unless @blog.present?
@other_blogs = Blog.where("context_id = ? and id != ?", @context, @blog.id).limit(10).order('created_at desc')
respond_to do |format|
format.html format.xml { render :xml => @blog }
end
end
|
#update ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'app/controllers/blog/blogs_controller.rb', line 58
def update
respond_to do |format|
if @blog.update_attributes(params[:blog])
format.xml { render :xml => @blog, :status => :created, :location => @blog }
format.html do
redirect_to(construct_blog_path(@blog, :show), :notice => "#{@blog.title} was successfully updated.")
end
else
format.html { render :action => :edit }
format.xml { render :xml => @blog.errors, :status => :unprocessable_entity }
end
end
end
|