Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # == Schema Information
- #
- # Table name: posts
- #
- # id :integer not null, primary key
- # body :string
- # created_at :datetime not null
- # updated_at :datetime not null
- # user_id :integer
- #
- class Post < ActiveRecord::Base
- validates :body, presence: true
- belongs_to :user
- end
- def create
- @post = Post.new(post_params)
- @post.user = current_user
- if @post.save
- redirect_to root_path
- else
- render :new
- end
- end
- <% if signed_in? && @post.user == current_user %>
- <%= link_to "Edit", edit_post_path(post) %>
- <%= link_to "Delete", post, method: :delete, data: {confirm: "Are you sure you want to delete this post?"} %>
- <%end%>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement