Class: Grandstand::PostsController
- Inherits:
-
MainController
- Object
- ApplicationController
- MainController
- Grandstand::PostsController
- Defined in:
- app/controllers/grandstand/posts_controller.rb
Instance Method Summary collapse
Methods inherited from MainController
Instance Method Details
#create ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'app/controllers/grandstand/posts_controller.rb', line 4 def create @post = Grandstand::Post.new(params[:post].merge(:user => current_user)) if @post.save flash[:success] = "#{@post.name} was successfully added" redirect_to grandstand_post_path(@post) else flash[:error] = 'There was a problem creating this post' if preview? render :preview, :layout => 'application' else render :new end end end |
#destroy ⇒ Object
19 20 21 22 23 |
# File 'app/controllers/grandstand/posts_controller.rb', line 19 def destroy @post.destroy flash[:delete] = 'Your post has been deleted' redirect_to grandstand_posts_path end |
#edit ⇒ Object
25 26 27 28 29 |
# File 'app/controllers/grandstand/posts_controller.rb', line 25 def edit if preview? render :preview, :layout => 'application' end end |
#index ⇒ Object
31 32 33 |
# File 'app/controllers/grandstand/posts_controller.rb', line 31 def index @posts = Grandstand::Post.all end |
#new ⇒ Object
35 36 37 38 39 40 |
# File 'app/controllers/grandstand/posts_controller.rb', line 35 def new @post = Grandstand::Post.new if preview? render :preview, :layout => 'application' end end |
#update ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/controllers/grandstand/posts_controller.rb', line 42 def update if @post.update_attributes(params[:post]) flash[:success] = "#{@post.name} was successfully saved" request.xhr? ? render(:json => {:status => :ok}) : redirect_to(grandstand_post_path(@post)) else flash[:error] = 'There was a problem saving this post' if preview? render :preview, :layout => 'application' else render :edit end end end |