2016-11-03 1 views
2

나는 사용자가 좋아하는 방을 선택할 수있는 작업 중 가장 좋아하는 작업을했지만 지금은이 오류가 발생하고 왜 작동하지 않는지 모릅니다.좋아하는 동작 가져 오기 오류 : 잘못된 인수 개수 (1, 예상 0)?

어떻게하면됩니까?

enter image description here

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 

답변

0

은 다음과 같습니다

if current_user && current_user.favorites.include?(@room) 
+0

나를 위해 완벽하게 작동했습니다. ;) 감사합니다! – trickydiddy

+1

@ 트릭디디 아무 probs! 그것이 당신을 위해 일했다면 대답을 받아 들일 수 있는지 확인하십시오. –

관련 문제