추가 기능이 포함 된 여러 개의 엔진이있는 레일즈 3 애플리케이션이 있습니다. 각 엔진은 고객이 액세스 권한을 구매할 수있는 별도의 서비스입니다.Rails 3 엔진의 경로를 호스트 응용 프로그램에서 사용할 수있게하려면 어떻게해야합니까?
그러나 컨트롤러 및 뷰에서 쉽게 사용할 수없는 엔진의 경로에 문제가 있습니다.
컨트롤러 :
class ClassroomsController < ApplicationController
..
respond_to :html
def index
respond_with(@classrooms = @company.classrooms.all)
end
def new
respond_with(@classroom = @company.classrooms.build)
end
..
end
app/views/classrooms/new.html.haml
: 엔진
= form_for @classroom do |f|
..
f.submit
config/routes.rb
: 응용 프로그램에서
MyEngineName::Engine.routes.draw do
resources :classrooms
end
config/routes.rb
:
lib/my_engine_name.rb
:
module MyEngineName
class Engine < ::Rails::Engine
end
end
이
NoMethodError in Classrooms#new
Showing app/views/classrooms/_form.html.haml where line #1 raised:
undefined method `hash_for_classrooms_path' for #<Module:0x00000104cff0f8>
에 /classrooms/new
결과로 이동을 시도하고 같은 오류의 다른보기 결과에서 classrooms_path
전화를 시도. 그러나 MyEngineName::Engine.routes.url_helpers.classrooms_path
으로 전화하여 작동 시키십시오. 내가 경로를 잘못 정의했을 수도 있지만 작동하는 다른 방법을 찾을 수 없다고 생각합니다.
Passenger (독립형 및 Apache 모듈)와 WEBrick (레일즈 서버) 모두로 앱을 실행 해 보았습니다. Git의 최신 Rails 사용 (7c920631ec3b314cfaa3a60d265de40cba3e8135
). 당신의 엔진
내 앱 경로에 마운트 통화를 제거, 그 수행 및 범위 지정 : 이제
을, 당신은 당신의 응용 프로그램 내부의 my_engine 도우미를 사용할 수 있습니다 ('scope '/ engine'do') 모든 것이 작동합니다. 고마워요 :) – PerfectlyNormal
엔진 경로를 작동시키는 데 필요한 다른 단계에 대한 정보에 감사드립니다. – bowsersenior
레일즈 3.1과 그 이후 버전의 경우,'map' 매개 변수를 블록에 제거하십시오 (전체'map |'부분 만 제거하십시오). –