やりたいことは、
microposts/index.html.haml
ーーーーーーーーー
|ポスト1 [いいね!]|
|ポスト2 [いいね!]|
|ポスト3 [いいね!]|
ーーーーーーーーー
のような一覧画面を作りたいということであっていますか?
であれば、質問者さんが挙げられているhttps://qiita.com/mikan3rd/items/21d716026b51331e53a1こちらのページがまさにそれをやっています。
具体的には、下記のように書けばできると思います。
ruby
1#views/microposts/index.html.haml
2#collectionに@micropostsを渡すと、@micropostsの数だけ繰り返し表示される
3= render partial: 'microposts/microposts', collection: @microposts
ruby
1#views/microposts/_microposts.html.haml
2= render micropost.content
3= render 'likes/like_links', micropost: micropost
ruby
1#views/likes/_like_links.html.haml
2#いいねボタン
3 if current_user.likes.find_by(micropost_id: micropost.id)
4 = link_to unlike_path(micropost.id), method: :delete, remote: true do
5 .btn.btn-default.glyphicon.glyphicon-heart{id: "heart-#{micropost.id}"}
6 = micropost.likes.count.to_s
7 - else
8 = link_to like_path(micropost.id), method: :post, remote: true do
9 .btn.btn-default.glyphicon.glyphicon-heart-empty{id: "heart-#{micropost.id}"}
10 = micropost.likes.count.to_s
的外れでしたらすみませんm(_ _)m
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/11/16 16:02