Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2014
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. class TextbooksController < ApplicationController
  2. before_action :signed_in_user
  3.  
  4. def create
  5. @textbook = current_user.textbooks.build(textbook_params)
  6. if @textbook.save
  7. flash[:success] = "Textbook added!"
  8. redirect_to root_url
  9. else
  10. render 'static_pages/home'
  11. end
  12. end
  13.  
  14. def destroy
  15. end
  16.  
  17.  
  18.  
  19. private
  20.  
  21.  
  22.  
  23. def textbook_params
  24. params.require(:textbook).permit(:content)
  25. end
  26.  
  27.  
  28. def correct_user
  29. @textbook = current_user.textbooks.find_by(id: params[:id])
  30. redirect_to root_url if @textbook.nil?
  31. end
  32. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement