Class: MicropostsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- MicropostsController
- Defined in:
- lib/generators/chapter11_3/solutions/templates/app/controllers/microposts_controller.rb
Instance Method Summary collapse
Methods inherited from ApplicationController
Instance Method Details
#create ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/generators/chapter11_3/solutions/templates/app/controllers/microposts_controller.rb', line 4 def create @micropost = current_user.microposts.build(params[:micropost]) if @micropost.save flash[:success] = "Micropost created!" redirect_to root_path else render 'pages/home' end end |
#destroy ⇒ Object
14 15 16 17 18 |
# File 'lib/generators/chapter11_3/solutions/templates/app/controllers/microposts_controller.rb', line 14 def destroy # .try will call the method given, unless the caller is nil current_user.microposts.find_by_id(params[:id]).try(:destroy) redirect_to :back end |