Class: PostsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- PostsController
- Defined in:
- app/controllers/posts_controller.rb
Instance Method Summary collapse
-
#cms ⇒ Object
GET /posts GET /posts.xml.
-
#create ⇒ Object
POST /posts POST /posts.xml.
-
#destroy ⇒ Object
DELETE /posts/1 DELETE /posts/1.xml.
-
#edit ⇒ Object
GET /posts/1/edit.
- #index ⇒ Object
-
#new ⇒ Object
GET /posts/new GET /posts/new.xml.
-
#show ⇒ Object
GET /posts/1 GET /posts/1.xml.
-
#update ⇒ Object
PUT /posts/1 PUT /posts/1.xml.
Instance Method Details
#cms ⇒ Object
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 [:action] = @post.template render end end |
#create ⇒ Object
POST /posts POST /posts.xml
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/controllers/posts_controller.rb', line 58 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(@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 |
#destroy ⇒ Object
DELETE /posts/1 DELETE /posts/1.xml
99 100 101 102 103 104 105 106 107 |
# File 'app/controllers/posts_controller.rb', line 99 def destroy @post = Post.find(params[:id]) @post.destroy respond_to do |format| format.html { redirect_to(posts_url) } format.xml { head :ok } end end |
#edit ⇒ Object
GET /posts/1/edit
52 53 54 |
# File 'app/controllers/posts_controller.rb', line 52 def edit @post = Post.find(params[:id]) end |
#index ⇒ Object
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 |
#new ⇒ Object
GET /posts/new GET /posts/new.xml
41 42 43 44 45 46 47 48 49 |
# File 'app/controllers/posts_controller.rb', line 41 def new @post = Post.new @categories = Category.find(:all) respond_to do |format| format.html # new.html.erb format.xml { render :xml => @post } end end |
#show ⇒ Object
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 = {} @post = Post.find(params[:id]) if(@post.layout != "application") then render :layout => @post.layout end if(@post.template!="") then [:action] = @post.template render end end |
#update ⇒ Object
PUT /posts/1 PUT /posts/1.xml
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'app/controllers/posts_controller.rb', line 78 def update @post = Post.find(params[:id]) params[:contents].each do |f| @content = Content.where(:post_id=>@post.id, :title=>f[0]).first @content.content = f[1] @content.save end respond_to do |format| if @post.update_attributes(params[:post]) format.html { redirect_to(@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 |