0
我有模型Drill
和Exercise
。練習屬於鑽和我都用的routes.rb:當路由在列表路由的輸出中列出時獲取ActionController :: RoutingError
resources :drills do
resources :exercises do
end
因此,這並不奇怪,看看從耙路線的輸出:
drill_exercises GET /drills/:drill_id/exercises(.:format) exercises#index
POST /drills/:drill_id/exercises(.:format) exercises#create
new_drill_exercise GET /drills/:drill_id/exercises/new(.:format) exercises#new
edit_drill_exercise GET /drills/:drill_id/exercises/:id/edit(.:format) exercises#edit
drill_exercise GET /drills/:drill_id/exercises/:id(.:format) exercises#show
PUT /drills/:drill_id/exercises/:id(.:format) exercises#update
DELETE /drills/:drill_id/exercises/:id(.:format) exercises#destroy
令人驚訝的是,這行代碼:
<%= link_to t('.new', :default => t("helpers.links.prompt")),
new_drill_exercise_path,
:class => 'btn btn-primary', :remote => true %>
是造成此錯誤:
ActionController::RoutingError at /drills/6/edit
沒有路由匹配{:動作=>「新」,:控制器=>「演習」}
儘管事實上,當我在打電話IRB一個controller.methods結果我得到的回覆是:new_drill_exercise_path
那麼......那是怎麼回事?
更多信息:
exercises_controller.rb
class ExercisesController < InheritedResources::Base
def new
@drill = Drill.find(params[:id])
@exercise = Exercise.new
respond_to do |format|
format.html { redirect_to(:action => 'edit') }
format.js
end
end
end
熱diggity該死的,你說得對!我一直在想,這個方法的名字會自動地將魔法物體拉進鑽孔中。 – vlasits 2013-03-20 14:20:04