Class: Transit::PostsController

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

Instance Method Summary collapse

Methods inherited from TransitController

#edit_mode_enabled?, #render

Instance Method Details

#collectionObject



6
7
8
# File 'app/controllers/transit/posts_controller.rb', line 6

def collection
  @posts ||= end_of_association_chain.page((params[:page] || 1), per: 20)
end

#createObject



10
11
12
13
14
15
16
17
# File 'app/controllers/transit/posts_controller.rb', line 10

def create
  @post = resource_class.new(params[:post])
  set_resource_ivar(@post)
  unless @post.save
    render action: 'new', error: 'Oops, looks like you forgot something!' and return
  end
  redirect_to transit.edit_polymorphic_path(resource), success: 'Your post was created!'
end

#destroyObject



27
28
29
# File 'app/controllers/transit/posts_controller.rb', line 27

def destroy
  destroy!(success: 'The selected post has been deleted.')
end

#updateObject



19
20
21
22
23
24
25
# File 'app/controllers/transit/posts_controller.rb', line 19

def update
  @post = Post.find(params[:id])
  unless @post.update_attributes(params[:post])
    render action: :edit, error: 'Looks like you forgot a couple fields' and return
  end
  redirect_to transit.edit_polymorphic_path(@post), success: 'Your post was updated.'
end