2
私はユーザーが好きな部屋で好きな作業をしていましたが、今ではこのエラーが発生していますが、なぜ動作しないのかわかりません。好きなアクション取得エラー:引数の数が間違っています(与えられた1、期待された0)?
どうすればこの作品を作成できますか?
show.html.erb
<% if current_user && current_user.favorites.exists(@room) %>
<%= link_to "unfavorite", favorite_room_path(@room, type: "unfavorite"), method: :put %>
<% else %>
<%= link_to "favorite", favorite_room_path(@room, type: "favorite"), method: :put %>
<% end %>
rooms_controller.rb
before_action :set_room, only: [:show, :favorite]
before_action :authenticate_user!, only: [:favorite]
def show
@photos = @room.photos
@booked = Reservation.where("room_id = ? AND user_id = ?", @room.id, current_user.id).present? if current_user
@reviews = @room.reviews
@hasReview = @reviews.find_by(user_id: current_user.id) if current_user
end
def favorite
type = params[:type]
if type == "favorite"
current_user.favorites << @room unless current_user.favorites.exists?(@room)
redirect_to wishlist_path, notice: 'You favorited #{@room.listing_name}'
elsif type == "unfavorite"
current_user.favorites.delete(@room)
redirect_to wishlist_path, notice: 'Unfavorited #{@room.listing_name}'
else
# Type missing, nothing happens
redirect_to wishlist_path, notice: 'Nothing happened.'
end
end
private
def set_room
@room = Room.find(params[:id])
end
完璧に機能しました! ;)ありがとう! – trickydiddy
@trickydiddy probs!それがあなたのために働いた場合は、答えを受け入れるようにしてください –