Conversation
186c4ee to
12b6c86
Compare
|
ready |
| return if logged_in? | ||
| store_location | ||
| flash[:danger] = t ".please_login" | ||
| redirect_to login_url |
| before_action :correct_user, only: :destroy | ||
|
|
||
| def create | ||
| @micropost = current_user.microposts.build micropost_params |
| def correct_user | ||
| @micropost = current_user.microposts.find_by id: params[:id] | ||
| redirect_to root_url if @micropost.nil? | ||
| end |
app/helpers/microposts_helper.rb
Outdated
| @@ -0,0 +1,2 @@ | |||
| module MicropostsHelper | |||
There was a problem hiding this comment.
File này chưa dùng đến bạn xóa đi nhé
app/models/micropost.rb
Outdated
| class Micropost < ApplicationRecord | ||
| belongs_to :user | ||
|
|
||
| default_scope -> {order created_at: :desc} |
There was a problem hiding this comment.
Bạn viết 1 scope để dùng chứ không dùng default_scope như này nhé
app/models/micropost.rb
Outdated
| validates :user_id, presence: true | ||
| validates :content, presence: true, | ||
| length: {maximum: Settings.model.microposts.size_post} | ||
| validate :picture_size |
There was a problem hiding this comment.
thừa khoảng trắng: => validate :picture_size
app/uploaders/picture_uploader.rb
Outdated
| class PictureUploader < CarrierWave::Uploader::Base | ||
| include CarrierWave::MiniMagick | ||
|
|
||
| process resize_to_limit: [400, 400] |
| @@ -0,0 +1,19 @@ | |||
| <%= form_for(@micropost) do |f| %> | |||
| </span> | ||
| <% end %> | ||
|
|
||
| <script type="text/javascript"> |
There was a problem hiding this comment.
move this code javascript into file .js
app/views/users/show.html.erb
Outdated
| <div class="col-md-8"> | ||
| <% if @user.microposts.any? %> | ||
| <h3> | ||
| <%= t ".micopost" %>(<%= @user.microposts.count %>) |
There was a problem hiding this comment.
Ở đây có đang chọc vào db từ view không nhỉ?
There was a problem hiding this comment.
không ạ, biến @user đã được định nghĩa tại controller rồi ạ, nên dữ liệu tại đây là do controller truyền đến
There was a problem hiding this comment.
Bạn tìm hiểu điểm giống và khác nhau giữa: count, size vs length nhé
|
commented |
854ebde to
f0cb72c
Compare
|
ready |
f0cb72c to
888ea6d
Compare
|
commented |
888ea6d to
7033881
Compare
|
ready |
app/assets/javascripts/custom.js
Outdated
| @@ -0,0 +1,8 @@ | |||
| $(document).ready(function(){ | |||
| $("#micropost_picture").bind("change", function() { | |||
There was a problem hiding this comment.
$("#micropost_picture").change() được không, bind() cũ rồi 😁
app/models/micropost.rb
Outdated
| class Micropost < ApplicationRecord | ||
| belongs_to :user | ||
|
|
||
| scope :time_desc, -> {order created_at: :desc} |
|
commented |
7033881 to
25b05b8
Compare
|
ready |
|
merged-ignore thư mục public/uploads đi nhé |
No description provided.