2016-07-20 2 views
0

안녕하세요. 모든 코드에서 모든 주제의 색인으로 다시 리디렉션되고 이론적으로 페이지로 다시 리디렉션하고 싶습니다.
이 바로 지금은 그냥 스탠드로 topics_path을 사용하고,이 페이지에 대한 내 컨트롤러입니다.내 주제/쇼 페이지로 리디렉션하는 방법은 무엇입니까?

class LikesController < ApplicationController 
    def index 
    end 
    def create 
    @bookmark = Bookmark.find(params[:bookmark_id]) 
    like = current_user.likes.build(bookmark: @bookmark) 
    if like.save 
     flash[:notice] = "Successfully liked bookmark." 
    else 
    flash.now[:alert] = 'Error in liking bookmark. Please try again.' 
    end 
    redirect_to topics_path 
end 

def destroy 
    @bookmark = Bookmark.find(params[:bookmark_id]) 
    like = current_user.likes.find(params[:id]) 
    # Get the bookmark from the params 
    # Find the current user's like with the ID in the params 

    if like.destroy 
    flash[:notice] = "Successfully unliked bookmark." 
    else 
    flash.now[:alert] = 'Error in unliking bookmark. Please try again.' 
    end 
    redirect_to topics_path 
end 
end 

이 내가 redirect_to
bookmarks_show GET /bookmarks/show(.:format) bookmarks#show

+1

당신이 TopicsController' – SpunkyLive

+0

'에서'index' 방법을 공유 할 수'데프
'@topics = Topic.all'
'인증 (@topics를) index''
는'잘 모르겠어요
end' 왜 내 markdown 구문이 제대로 작동하지 않습니다. – SinGar

답변

1

이었다 레이크 노선에서 라인 당신이 만약 특정 주제의 페이지로 리디렉션하려는 경우 topicUid를 매개 변수로 전달하여 리디렉션에 사용할 수 있도록해야합니다. 그냥 사용 리디렉션, 당신의 생성 작업에 그런

<% form_for @like do |f| %> 
    <%= f.hidden_field :topic_id, @topic.id %> 

: (분명히 코드가 다를 수 완전히이 만드는 주) :

하면 예를 사용하는 양식/링크로 추가 그 예 :

def create 
    @bookmark = Bookmark.find(params[:bookmark_id]) 
    like = current_user.likes.build(bookmark: @bookmark) 
    if like.save 
    flash[:notice] = "Successfully liked bookmark." 
    else 
    flash.now[:alert] = 'Error in liking bookmark. Please try again.' 
    end 
    redirect_to topic_path(:id => params[:topic_id]) 
end 

참고 : 다른 페이지를 사용하려는 경우 (예 : 북마크 페이지)를 대신에를 사용 ...이 당신이 보는 바와 같이 "일반 하우투는"이 아닌 "바로이 코드를 사용하다 그것 여기 ":)

관련 문제