이 link_to 메서드가 내 루트 경로로 리디렉션되는 이유는 무엇입니까?Link_to 메서드가 루트 경로로 계속 리디렉션 함
사용자 컨트롤러 :
def show
@user = User.find(params[:id])
@user.comments.build
@comment = Comment.new
@user.votes.build
@vote = Vote.new
end
def vote:
@comment = Comment.find(params[:id])
Vote.create!(voteable_id: params[:id], voteable_type: 'Comments')
@user = User.find(params[:id])
redirect_to @user
end
사용자보기 :
<%= link_to "vote", vote_comment_path(:id => comment.id), method: :post, :class=> "btn %>
Routes.rb :
post 'comments/:id/vote' => 'comments#vote', as: 'vote_comment'
resources :users do
resources :comments
resources :ratings
resources :votes
end
나는 사용자에게 다시 리디렉션 투표를 클릭 기다리고 있었다
, 대신 내 홈페이지로 간다.
같은 방법으로 params[:id]
을 두 번 사용할 수 있습니까?
당신이 UsersController # 쇼 코드를 제공 할 수있다? – emaxi
경로 파일을 표시하십시오. – Substantial
'redirect_to @ user'를'redirect_to user_path (@user)'로 변경하십시오. –