1

Railsアプリを持っています。すべてのコントローラーは、から継承するからBaseController継承しApplicationController::Baseます。これは、パーシャルを個別の名前空間に編成するためのものです。それは素晴らしい働きをします。

ここに問題があります。

Devise gemを使用しようとしていますが、Devise::SessionsControllerBaseという名前のフォルダーに保存されているパーシャルが見つかりません。Devise::SessionsController私の解決策は、次のように継承したローカルコントローラーを作成することでした。

module Account
  class SessionsController < Devise::SessionsController
  end
end

問題は、このローカルがまだ私のパーシャルを見つけることができるようにSessionsController私から継承する必要があるということです。BaseControllerわかる?

BaseControllerコード:

module Account
  class BaseController < ApplicationController
  end
end

ApplicationControllerコード:

class ApplicationController < ActionController::Base
  protect_from_forgery

end

I've been reading about mixins, but can't see how I can use mixins to solve this problem, because I don't have any methods to import from the class ...

4

1 に答える 1

0

The solution to this is simply to make the path to your partials more explicit. So in my example, in my Application layout file I changed the partial path from this:

<%= render "menu" %>

to this:

<%= render "account/base/menu" %>

This works because rails looks for the partial in the regular places, but can't find it and throws an error. Specifying exactly where the partial can be found when putting the partial into your HTML solves the problem of Rails or any gems from not knowing where your partials are.

于 2013-03-10T18:09:16.693 に答える