Class: Transit::PostsController
Instance Method Summary
collapse
#edit_mode_enabled?, #render
Instance Method Details
#collection ⇒ Object
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
|
#create ⇒ Object
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
|
#destroy ⇒ Object
27
28
29
|
# File 'app/controllers/transit/posts_controller.rb', line 27
def destroy
destroy!(success: 'The selected post has been deleted.')
end
|
#update ⇒ Object
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
|