내 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