Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. # == Schema Information
  2. #
  3. # Table name: posts
  4. #
  5. # id :integer not null, primary key
  6. # body :string
  7. # created_at :datetime not null
  8. # updated_at :datetime not null
  9. # user_id :integer
  10. #
  11.  
  12. class Post < ActiveRecord::Base
  13. validates :body, presence: true
  14. belongs_to :user
  15. end
  16.  
  17. def create
  18. @post = Post.new(post_params)
  19. @post.user = current_user
  20. if @post.save
  21. redirect_to root_path
  22. else
  23. render :new
  24. end
  25. end
  26.  
  27. <% if signed_in? && @post.user == current_user %>
  28.  
  29. <%= link_to "Edit", edit_post_path(post) %>
  30. <%= link_to "Delete", post, method: :delete, data: {confirm: "Are you sure you want to delete this post?"} %>
  31. <%end%>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement