Advertisement
aacode20

articles_controller.rb

Apr 6th, 2019
737
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. class ArticlesController < ApplicationController
  2. def new
  3. @article = Article.new
  4. end
  5.  
  6. def create
  7. @article = Article.new(article_params)
  8.  
  9. if @article.save
  10. redirect_to @article
  11. else
  12. render 'new'
  13. end
  14. end
  15.  
  16. def show
  17. @article = Article.find(params[:id])
  18. @owner = 'Armand'
  19. end
  20.  
  21. def edit
  22. @article = Article.find(params[:id])
  23. end
  24.  
  25. def update
  26. @article = Article.find(params[:id])
  27.  
  28. if Article.update(article_params)
  29. redirect_to @article
  30. else
  31. render 'edit'
  32. end
  33. end
  34.  
  35. def index
  36. @articles = Article.all
  37. end
  38.  
  39. private
  40. def article_params
  41. params.require(:article).permit(:title, :text)
  42. end
  43. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement