0
我試圖遵循這個線程解決方案的方法 - Rails 3 link or button that executes action in controller訪問中通過按鈕/鏈接軌控制器
我定義的:在我的routes.rb文件update_question:
resources :surveys do
put :update_question, :on => :member
end
,並在我的控制器:
class SurveysController < ApplicationController
before_action :set_survey, only: [:show, :edit, :update, :destroy]
before_action :set_question
# GET /surveys
# GET /surveys.json
def index
@surveys = Survey.all
end
# GET /surveys/1
# GET /surveys/1.json
def show
end
def survey
@survey = Survey.find(params[:survey_id])
end
# GET /surveys/new
def new
@survey = Survey.new
end
# GET /surveys/1/edit
def edit
end
def update_question
flash[:alert] = "getting there man"
end
和上市的HTML這裏的鏈接:
<%= link_to "Next Question", update_question_survey_path(@survey), {:method => :put} %>
然而,當我點擊鏈接我得到這個錯誤:
Template is missing
Missing template surveys/update_question, application/update_question with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee]}.
這似乎是逃避,它在尋找一個觀點 - 但實際上我只是希望它在我的調查控制器運行的方法和更新問題正在顯示。也許我正在以這種錯誤的方式去做,任何幫助/建議都非常感謝!
啊,是非常有意義的 - 我可以只設置我的新PARAMS以顯示新的問題。 –