Complete CRUD actions for microposts
This commit is contained in:
parent
2014730610
commit
8759a9062c
|
@ -2,7 +2,7 @@
|
|||
|
||||
class MicropostsController < ApplicationController
|
||||
skip_before_action :require_login, only: [:index, :show]
|
||||
before_action :set_micropost, only: [:show]
|
||||
before_action :set_micropost, only: [:show, :edit, :update, :destroy]
|
||||
|
||||
def index
|
||||
@microposts = Micropost.all.order(created_at: :desc)
|
||||
|
@ -24,6 +24,24 @@ class MicropostsController < ApplicationController
|
|||
|
||||
def show; end
|
||||
|
||||
def edit; end
|
||||
|
||||
def update
|
||||
if @micropost.update(micropost_params)
|
||||
redirect_to @micropost, notice: t(".updated")
|
||||
else
|
||||
render :edit, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @micropost.destroy
|
||||
redirect_to microposts_path, notice: t(".deleted")
|
||||
else
|
||||
render :edit, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def micropost_params
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<div class="micropost">
|
||||
<%= micropost.content %>
|
||||
<div class="created_at">
|
||||
<%= link_to "Edit", edit_micropost_path(micropost) if micropost.user == current_user %>
|
||||
<%= link_to micropost.created_at.strftime("%Y-%m-%d %H:%M"), micropost %>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
<% @title = t(".edit") %>
|
||||
|
||||
<%= render partial: "form",
|
||||
locals: {
|
||||
user: @user,
|
||||
button_text: t(".edit"),
|
||||
title: t(".edit"),
|
||||
} %>
|
||||
|
||||
<%= link_to t(".delete"), @micropost, data: { turbo_method: :delete, turbo_confirm: t(".confirm") } %>
|
|
@ -1,3 +1,5 @@
|
|||
en:
|
||||
microposts:
|
||||
created: Successfully created μpost
|
||||
updated: Successfully updated μpost
|
||||
deleted: Successfully deleted μpost
|
||||
|
|
|
@ -6,4 +6,8 @@ en:
|
|||
new: New μpost
|
||||
new:
|
||||
create: Create μpost
|
||||
edit:
|
||||
edit: Edit μpost
|
||||
delete: Delete μpost
|
||||
confirm: Are you sure you want to delete this μpost?
|
||||
|
||||
|
|
|
@ -12,5 +12,5 @@ Rails.application.routes.draw do
|
|||
delete "log_out", to: "sessions#destroy_session"
|
||||
get "confirm_email", to: "email_confirmations#confirm"
|
||||
|
||||
resources :microposts, only: [:index, :new, :create, :show]
|
||||
resources :microposts
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue