2014-11-24 5 views
0

내 link_to가 내가 생각한대로 작동하지 않는 이유를 알아 내려고하고 있습니다. 신청서에는 경품 데이터베이스가 있습니다. 사용자가 link_to를 클릭하면 컨트롤러는 선택된 액션 (이 경우 "result1")에 액세스하고 결과 페이지 뷰에서 액션 메소드를 수행해야합니다. 테스트에서 link_to가 : action => 'result1'을 완전히 무시하는 것처럼 보이고 Show 메서드를 수행하는 것만 기본값으로 설정됩니다.Link_to : 액션은 컨트롤러 메소드를 호출하지 않습니다. - 레일즈 4

link_to가 을 완전히 무시하는 이유는 무엇입니까? action => 'result1'?

먼저보기 :

<%=link_to 'result', resultpage_path, :controller => 'resultpage', :action => 'result1', :class => 'btn btn-default'%> 

Resultpage 컨트롤러 : resultspage :

class ResultpageController < ApplicationController 

def index 
end 

# regardless of what is in the :action =>, the controller always calls Show. 
def show 
    @prize = Prize.first 
    render :index 
end 

# if i make the :action => 'result1', the controller still calls Show. 
def result1 
    @prize = Prize.last 
    render :index 
end 

결과보기 컨트롤러/resultpage_controller.rb 전망// start.html.erb보기 시작 /index.html.erb

<h2><%= @prize.title %></h2> 
    <p><%= @prize.description %></p> 

경로 :

resources :resultpage do 
    get 'index' 
    get 'show' 
end 

resources :prizes 

답변

0

투어 컨트롤러 같은 내용

resources :resulpages do 
    get :result1 
end 

사용과 같은 링크

= link_to 'result', result1_resultpage_paths 

과 경로를 확인하고 수정

class ResultpageController < ApplicationController 

그리고이 기사를주의 깊게 읽으십시오.

관련 문제