songに紐づくcommentに「いいね」をするボタンを、commentの中の、index.html.erbを通してブラウザに表示したいのですが、以下のコードでやってみると エラーが出ます。
<%= link_to good_song_comment_path(@song,comment), method: :put, class: "portfolio-link" do %>の(@song,comment)を変えることでうまくいくと思うのですが、どう変更してもだめです。
解決策がお分かりでしたら、回答よろしくおねがいします。
<% @comments.each do |comment| %> <div class="col-md-4 col-sm-6 portfolio-item"> <a class="portfolio-link" data-toggle="modal" href="#portfolioModal1"> <%= link_to good_song_comment_path(@song,comment), method: :put, class: "portfolio-link" do %> <div class="portfolio-hover"> <div class="portfolio-hover-content"> <i class="fa fa-plus fa-3x"> いいね </i> </div> </div> <img class="img-fluid" src="/assets/noimage.jpg" alt=""> <% end %> </a> <div class="portfolio-caption"> <h4> <ui> <%= link_to comment.song.title, song_path(comment.song) %><br> <%= link_to comment.body,comment %> </ui> </h4> </div> </div> <% end %>
good_song_comment PUT /songs/:song_id/comments/:id/good(.:format) comments#upvote
class CommentsController < ApplicationController before_action :set_comment, only: [:show, :edit, :update, :destroy, :upvote] before_filter :authenticate_user! respond_to :html def index if params[:user_id] @user = User.find(params[:user_id]) @comments = @user.comments else @comments = Comment.all end end def show @comment = Comment.find(params[:id]) end def upvote @comment.upvote_by current_user redirect_to :back end private def set_comment @comment = Comment.find(params[:id]) end def comment_params params.require(:comment).permit(:song_id, :body, :user_id, :image) end end
あなたの回答
tips
プレビュー