Class: Grandstand::PostsController

Inherits:
MainController
  • Object
show all
Defined in:
app/controllers/grandstand/posts_controller.rb

Instance Method Summary collapse

Methods inherited from MainController

#expand

Instance Method Details

#createObject



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

#destroyObject



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

#editObject



25
26
27
28
29
# File 'app/controllers/grandstand/posts_controller.rb', line 25

def edit
  if preview?
    render :preview, :layout => 'application'
  end
end

#indexObject



31
32
33
# File 'app/controllers/grandstand/posts_controller.rb', line 31

def index
  @posts = Grandstand::Post.all
end

#newObject



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

#updateObject



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