3

Refinery をマウントして/おり、既存のアプリに統合しようとしています。(私はRailsも初めてです:)

views/refinery/_header.html.erbログイン/ログアウト/プロファイルの編集メニューをページの上部に追加するようにオーバーライドしました。

<% if current_user %>
    <%= link_to current_user.email, :controller => "users", :action => :edit, :id => current_user.id %>
    <%= link_to "Log out", main_app.logout_url %>
<% else %>
    <%= link_to "Sign Up", main_app.signup_url %> or
    <%= link_to "Log In", main_app.login_url %>
<% end %>

ただし、このコードはロード時にエラーを生成します。

No route matches {:controller=>"refinery/users", :action=>"edit", :id=>"a7ruusdt"}

質問

  1. _header.html.erb をオーバーライドすることは、この目標を達成するためのベスト プラクティスですか?
  2. その場合、Refinery ヘッダー内からアプリのコントローラーにアクセスするにはどうすればよいですか? つまり、エンジン内からメイン アプリのコントローラーにアクセスするにはどうすればよいでしょうか。

rake routes出力は次のとおりです。

$ rake routes
       logout GET    /logout(.:format)             sessions#destroy
        login GET    /login(.:format)              sessions#new
       signup GET    /signup(.:format)             users#new
        users GET    /users(.:format)              users#index
              POST   /users(.:format)              users#create
     new_user GET    /users/new(.:format)          users#new
    edit_user GET    /users/:id/edit(.:format)     users#edit
         user GET    /users/:id(.:format)          users#show
              PUT    /users/:id(.:format)          users#update
              DELETE /users/:id(.:format)          users#destroy
     sessions GET    /sessions(.:format)           sessions#index
              POST   /sessions(.:format)           sessions#create
  new_session GET    /sessions/new(.:format)       sessions#new
 edit_session GET    /sessions/:id/edit(.:format)  sessions#edit
      session GET    /sessions/:id(.:format)       sessions#show
              PUT    /sessions/:id(.:format)       sessions#update
              DELETE /sessions/:id(.:format)       sessions#destroy
    followers GET    /followers(.:format)          followers#index
              POST   /followers(.:format)          followers#create
 new_follower GET    /followers/new(.:format)      followers#new
edit_follower GET    /followers/:id/edit(.:format) followers#edit
     follower GET    /followers/:id(.:format)      followers#show
              PUT    /followers/:id(.:format)      followers#update
              DELETE /followers/:id(.:format)      followers#destroy
     refinery        /                             Refinery::Core::Engine

Routes for Refinery::Core::Engine:
                                       /system/resources/*dragonfly(.:format)       <Dragonfly::App name=:refinery_resources >
        insert_admin_resources GET     /refinery/resources/insert(.:format)         refinery/admin/resources#insert
               admin_resources GET     /refinery/resources(.:format)                refinery/admin/resources#index
                               POST    /refinery/resources(.:format)                refinery/admin/resources#create
            new_admin_resource GET     /refinery/resources/new(.:format)            refinery/admin/resources#new
           edit_admin_resource GET     /refinery/resources/:id/edit(.:format)       refinery/admin/resources#edit
                admin_resource PUT     /refinery/resources/:id(.:format)            refinery/admin/resources#update
                               DELETE  /refinery/resources/:id(.:format)            refinery/admin/resources#destroy
                                       /system/images/*dragonfly(.:format)          <Dragonfly::App name=:refinery_images >
           insert_admin_images GET     /refinery/images/insert(.:format)            refinery/admin/images#insert
                  admin_images GET     /refinery/images(.:format)                   refinery/admin/images#index
                               POST    /refinery/images(.:format)                   refinery/admin/images#create
               new_admin_image GET     /refinery/images/new(.:format)               refinery/admin/images#new
              edit_admin_image GET     /refinery/images/:id/edit(.:format)          refinery/admin/images#edit
                   admin_image PUT     /refinery/images/:id(.:format)               refinery/admin/images#update
                               DELETE  /refinery/images/:id(.:format)               refinery/admin/images#destroy
               admin_dashboard GET     /refinery/dashboard(.:format)                refinery/admin/dashboard#index
 admin_disable_upgrade_message         /refinery/disable_upgrade_message(.:format)  refinery/admin/dashboard#disable_upgrade_message
                                       /system/resources/*dragonfly(.:format)       <Dragonfly::App name=:refinery_resources >
                               GET     /refinery/resources/insert(.:format)         refinery/admin/resources#insert
                               GET     /refinery/resources(.:format)                refinery/admin/resources#index
                               POST    /refinery/resources(.:format)                refinery/admin/resources#create
                               GET     /refinery/resources/new(.:format)            refinery/admin/resources#new
                               GET     /refinery/resources/:id/edit(.:format)       refinery/admin/resources#edit
                               PUT     /refinery/resources/:id(.:format)            refinery/admin/resources#update
                               DELETE  /refinery/resources/:id(.:format)            refinery/admin/resources#destroy
                                       /system/images/*dragonfly(.:format)          <Dragonfly::App name=:refinery_images >
                               GET     /refinery/images/insert(.:format)            refinery/admin/images#insert
                               GET     /refinery/images(.:format)                   refinery/admin/images#index
                               POST    /refinery/images(.:format)                   refinery/admin/images#create
                               GET     /refinery/images/new(.:format)               refinery/admin/images#new
                               GET     /refinery/images/:id/edit(.:format)          refinery/admin/images#edit
                               PUT     /refinery/images/:id(.:format)               refinery/admin/images#update
                               DELETE  /refinery/images/:id(.:format)               refinery/admin/images#destroy
               admin_dashboard GET     /refinery/dashboard(.:format)                refinery/admin/dashboard#inde
 admin_disable_upgrade_message         /refinery/disable_upgrade_message(.:format)  refinery/admin/dashboard#disable_upgrade_message
                                       /system/resources/*dragonfly(.:format)       <Dragonfly::App name=:refinery_resources >
                               GET     /refinery/resources/insert(.:format)         refinery/admin/resources#insert
                               GET     /refinery/resources(.:format)                refinery/admin/resources#index
                               POST    /refinery/resources(.:format)                refinery/admin/resources#create
                               GET     /refinery/resources/new(.:format)            refinery/admin/resources#new
                               GET     /refinery/resources/:id/edit(.:format)       refinery/admin/resources#edit
                               PUT     /refinery/resources/:id(.:format)            refinery/admin/resources#update
                               DELETE  /refinery/resources/:id(.:format)            refinery/admin/resources#destroy
                                       /system/images/*dragonfly(.:format)          <Dragonfly::App name=:refinery_images >
                               GET     /refinery/images/insert(.:format)            refinery/admin/images#insert
                               GET     /refinery/images(.:format)                   refinery/admin/images#index
                               POST    /refinery/images(.:format)                   refinery/admin/images#create
                               GET     /refinery/images/new(.:format)               refinery/admin/images#new
                               GET     /refinery/images/:id/edit(.:format)          refinery/admin/images#edit
                               PUT     /refinery/images/:id(.:format)               refinery/admin/images#update
                               DELETE  /refinery/images/:id(.:format)               refinery/admin/images#destroy
               admin_dashboard GET     /refinery/dashboard(.:format)                refinery/admin/dashboard#index
 admin_disable_upgrade_message         /refinery/disable_upgrade_message(.:format)  refinery/admin/dashboard#disable_upgrade_message
                          root GET     /                                            refinery/pages#home
                 preview_pages POST    /pages/preview(.:format)                     refinery/pages#preview
                  preview_page GET|PUT /pages/*path/preview(.:format)               refinery/pages#preview
                          page GET     /pages/:id(.:format)                         refinery/pages#show
                         admin GET     /refinery/pages/*path/edit(.:format)         refinery/admin/pages#edit
          admin_children_pages GET     /refinery/pages/*path/children(.:format)     refinery/admin/pages#children
                               PUT     /refinery/pages/*path(.:format)              refinery/admin/pages#update
                               DELETE  /refinery/pages/*path(.:format)              refinery/admin/pages#destroy
  update_positions_admin_pages POST    /refinery/pages/update_positions(.:format)   refinery/admin/pages#update_positions
                   admin_pages GET     /refinery/pages(.:format)                    refinery/admin/pages#index
                               POST    /refinery/pages(.:format)                    refinery/admin/pages#create
                new_admin_page GET     /refinery/pages/new(.:format)                refinery/admin/pages#new
               edit_admin_page GET     /refinery/pages/:id/edit(.:format)           refinery/admin/pages#edit
                    admin_page PUT     /refinery/pages/:id(.:format)                refinery/admin/pages#update
                               DELETE  /refinery/pages/:id(.:format)                refinery/admin/pages#destroy
   link_to_admin_pages_dialogs GET     /refinery/pages_dialogs/link_to(.:format)    refinery/admin/pages_dialogs#link_to
  test_url_admin_pages_dialogs GET     /refinery/pages_dialogs/test_url(.:format)   refinery/admin/pages_dialogs#test_url
test_email_admin_pages_dialogs GET     /refinery/pages_dialogs/test_email(.:format) refinery/admin/pages_dialogs#test_email
              admin_page_parts POST    /refinery/page_parts(.:format)               refinery/admin/page_parts#create
           new_admin_page_part GET     /refinery/page_parts/new(.:format)           refinery/admin/page_parts#new
               admin_page_part DELETE  /refinery/page_parts/:id(.:format)           refinery/admin/page_parts#destroy
     new_refinery_user_session GET     /refinery/users/login(.:format)              refinery/sessions#new
         refinery_user_session POST    /refinery/users/login(.:format)              refinery/sessions#create
 destroy_refinery_user_session DELETE  /refinery/users/logout(.:format)             refinery/sessions#destroy
        refinery_user_password POST    /refinery/users/password(.:format)           refinery/passwords#create
    new_refinery_user_password GET     /refinery/users/password/new(.:format)       refinery/passwords#new
   edit_refinery_user_password GET     /refinery/users/password/edit(.:format)      refinery/passwords#edit
                               PUT     /refinery/users/password(.:format)           refinery/passwords#update
     new_refinery_user_session GET     /refinery/login(.:format)                    refinery/sessions#new
 destroy_refinery_user_session GET     /refinery/logout(.:format)                   refinery/sessions#destroy
new_refinery_user_registration GET     /refinery/users/register(.:format)           refinery/users#new
    refinery_user_registration POST    /refinery/users/register(.:format)           refinery/users#create
                     wymiframe GET     /wymiframe(/:id)(.:format)                   refinery/fast#wymiframe
                       message GET     /refinery/message(.:format)                  refinery/fast#message
                    admin_root         /refinery(.:format)                          refinery/admin/dashboard#index
                  admin_dialog GET     /refinery/dialogs/:id(.:format)              refinery/admin/dialogs#show
refinery_update_menu_positions         /refinery/update_menu_positions(.:format)    refinery/admin/core#update_plugin_positions
                               GET     /sitemap.xml(.:format)                       refinery/sitemap#index {:format=>"xml"}
                   admin_users GET     /refinery/users(.:format)                    refinery/admin/users#index
                               POST    /refinery/users(.:format)                    refinery/admin/users#create
                new_admin_user GET     /refinery/users/new(.:format)                refinery/admin/users#new
               edit_admin_user GET     /refinery/users/:id/edit(.:format)           refinery/admin/users#edit
                    admin_user PUT     /refinery/users/:id(.:format)                refinery/admin/users#update
                               DELETE  /refinery/users/:id(.:format)                refinery/admin/users#destroy
                                       /refinery/*path(.:format)                    refinery/admin/base#error_404
                               GET     /refinery/users(.:format)                    refinery/admin/users#index
                               POST    /refinery/users(.:format)                    refinery/admin/users#create
                               GET     /refinery/users/new(.:format)                refinery/admin/users#new
                               GET     /refinery/users/:id/edit(.:format)           refinery/admin/users#edit
                               PUT     /refinery/users/:id(.:format)                refinery/admin/users#update
                               DELETE  /refinery/users/:id(.:format)                refinery/admin/users#destroy
                                       /refinery/*path(.:format)                    refinery/admin/base#error_404
               marketable_page GET     /*path(.:format)                             refinery/pages#show
                               GET     /refinery/users(.:format)                    refinery/admin/users#index
                               POST    /refinery/users(.:format)                    refinery/admin/users#create
                               GET     /refinery/users/new(.:format)                refinery/admin/users#new
                               GET     /refinery/users/:id/edit(.:format)           refinery/admin/users#edit
                               PUT     /refinery/users/:id(.:format)                refinery/admin/users#update
                               DELETE  /refinery/users/:id(.:format)                refinery/admin/users#destroy
                                       /refinery/*path(.:format)                    refinery/admin/base#error_404
                               GET     /refinery/users(.:format)                    refinery/admin/users#index
                               POST    /refinery/users(.:format)                    refinery/admin/users#create
                               GET     /refinery/users/new(.:format)                refinery/admin/users#new
                               GET     /refinery/users/:id/edit(.:format)           refinery/admin/users#edit
                               PUT     /refinery/users/:id(.:format)                refinery/admin/users#update
                               DELETE  /refinery/users/:id(.:format)                refinery/admin/users#destroy
                                       /refinery/*path(.:format)                    refinery/admin/base#error_404

注: 私は独自の認証を作成しましたが、Refinery の認証と統合されていません。

4

1 に答える 1

1

ルートの前にmain_appと"engine_name"を使用して、目的のルートにアクセスできます。Foo::EngineのようなFooというエンジンがあるとします。

main_app.pages_url
foo.pages_url
于 2013-02-02T18:43:02.050 に答える