Advertisement
xenodesystems

Controlador de Posts - Blog en Rails

Jun 9th, 2012
583
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.72 KB | None | 0 0
  1. class PostsController < ApplicationController
  2.  
  3.   def index
  4.     @posts = Post.all
  5.   end
  6.  
  7.     def show
  8.         @post = Post.find(params[:id])
  9.     end
  10.    
  11.     def new
  12.         @post = Post.new
  13.     end
  14.  
  15.     def create
  16.         @post = Post.new(params[:post])
  17.  
  18.         if @post.save
  19.             redirect_to posts_path, :notice => "Tu post se ha salvado"
  20.         else
  21.             render "new"
  22.         end
  23.     end
  24.    
  25.     def edit
  26.     @post = Post.find(params[:id])
  27.     end
  28.  
  29.     def update
  30.     @post = Post.find(params[:id])
  31.    
  32.     if @post.update_attributes(params[:post])
  33.         redirect_to posts_path, :notice => "Tu post se ha actualizado"
  34.     else
  35.         render "edit"
  36.     end
  37. end
  38.  
  39.     def destroy
  40.     @post = Post.find(params[:id])
  41.     @post.destroy
  42.     redirect_to posts_path, :notice => "Tu post se ha borrado"
  43.     end
  44. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement