Class: PostsController

Inherits:
AbstractAdminController show all
Defined in:
app/controllers/posts_controller.rb

Instance Method Summary collapse

Methods inherited from AbstractAdminController

#after_sign_in_path_for

Instance Method Details

#cmsObject

GET /posts GET /posts.xml



5
6
7
8
9
10
11
12
13
14
# File 'app/controllers/posts_controller.rb', line 5

def cms
  @post = Post.find(params[:id])
  if(@post.layout != "application") then
    render :layout => @post.layout
  end
  if(@post.template) then
    render_options[:action] = @post.template
    render render_options
  end
end

#createObject

POST /posts POST /posts.xml



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

def create
  @post = Post.new(params[:post])
  @post.admin_id = current_admin.id
  #params[:contents].each do |f|
  #  @post.contents << Content.create(:title=>f[0], :content=>f[1])
  #end

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

#destroyObject

DELETE /posts/1 DELETE /posts/1.xml



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

def destroy
  @post = Post.find(params[:id])
  @post.destroy

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

#editObject

GET /posts/1/edit



55
56
57
# File 'app/controllers/posts_controller.rb', line 55

def edit
  @post = Post.find(params[:id])
end

#indexObject



15
16
17
18
19
20
21
22
# File 'app/controllers/posts_controller.rb', line 15

def index
  @posts = Post.all

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

#newObject

GET /posts/new GET /posts/new.xml



41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/posts_controller.rb', line 41

def new
  @post = Post.new
  @categories = Category.find(:all)
  1.times do
    content = @post.contents.build
  end

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

#showObject

GET /posts/1 GET /posts/1.xml



26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/posts_controller.rb', line 26

def show
  render_options = {}
  @post = Post.find(params[:id])
  if(@post.layout != "application") then
    render :layout => @post.layout
  end
  if(@post.template!="") then
    render_options[:action] = @post.template
    render render_options
  end

end

#updateObject

PUT /posts/1 PUT /posts/1.xml



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

def update
  @post = Post.find(params[:id])

  respond_to do |format|
    if @post.update_attributes(params[:post])
      format.html { redirect_to([:admin, @post], :notice => 'Post was successfully updated.') }
      format.xml  { head :ok }
    else
      format.html { render :action => "edit" }
      format.xml  { render :xml => @post.errors, :status => :unprocessable_entity }
    end
  end
end